我正在ggplot2中绘制一个十六进制图。一个图例显示了六边形的填充(计数),但没有显示六边形的实际热缩放(预测)。
我如何摆脱计数的图例,但让它显示实际上是什么被热缩放(预测)。下面是我的代码和我所指的图片。
FF1xBARHH <- ggplot(FFxBARHH, aes(x = plate_x, y = plate_z, z = Prediction)) +
stat_summary_hex(fun = mean, bins = 9) +
stat_summary_hex(geom = "text", aes(label = after_stat(value)), fun = length,
bins = 9) +
scale_fill_gradient2(low = "blue", mid = "white", high = "red", midpoint = 0.240) +
xlim(c(2,-2)) +
ylim(c(0,5)) +
coord_fixed(0.8)+
labs(title = "Gerrit Cole Fastball April 2022 ExAVG Map RHH")+
annotate('rect', xmin = -0.85, xmax = 0.85, ymin = 1.6, ymax = 3.5,
fill = 'black', color = 'black', alpha = 0.0001, size = 1)
FFxBARHH <- structure(list(Prediction = c(0.002, 0.598, 0, 0, 0.688, 0.104,
0.908, 0.042, 0.142, 0.872, 0.034, 0.916, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0), pitch_type = c("FF", "FF", "FF", "FF", "FF", "FF",
"FF", "FF", "FF", "FF", "FF", "FF", "FF", "FF", "FF", "FF", "FF",
"FF", "FF", "FF", "FF", "FF"), game_date = structure(c(19112,
19112, 19112, 19106, 19106, 19095, 19095, 19095, 19095, 19095,
19095, 19090, 19112, 19112, 19112, 19106, 19106, 19095, 19095,
19095, 19083, 19083), class = "Date"), release_speed = c(97.9,
96.6, 96.2, 98, 95.4, 99.8, 97.5, 97.6, 96.8, 95.7, 94.7, 99.1,
98.7, 98.1, 96.2, 97.7, 98.6, 99.3, 98.9, 97.9, 96.2, 96.8),
player_name = c("Cole, Gerrit", "Cole, Gerrit", "Cole, Gerrit",
"Cole, Gerrit", "Cole, Gerrit", "Cole, Gerrit", "Cole, Gerrit",
"Cole, Gerrit", "Cole, Gerrit", "Cole, Gerrit", "Cole, Gerrit",
"Cole, Gerrit", "Cole, Gerrit", "Cole, Gerrit", "Cole, Gerrit",
"Cole, Gerrit", "Cole, Gerrit", "Cole, Gerrit", "Cole, Gerrit",
"Cole, Gerrit", "Cole, Gerrit", "Cole, Gerrit"), pitcher = c(543037,
543037, 543037, 543037, 543037, 543037, 543037, 543037, 543037,
543037, 543037, 543037, 543037, 543037, 543037, 543037, 543037,
543037, 543037, 543037, 543037, 543037), events = c("field_out",
"single", "field_out", "field_out", "field_out", "field_out",
"double", "field_out", "field_out", "double", "field_out",
"double", "strikeout", "strikeout", "strikeout", "strikeout",
"strikeout", "strikeout", "strikeout", "strikeout", "strikeout",
"strikeout"), description = c("hit_into_play", "hit_into_play",
"hit_into_play", "hit_into_play", "hit_into_play", "hit_into_play",
"hit_into_play", "hit_into_play", "hit_into_play", "hit_into_play",
"hit_into_play", "hit_into_play", "called_strike", "swinging_strike",
"called_strike", "called_strike", "foul_tip", "foul_tip",
"swinging_strike", "called_strike", "called_strike", "called_strike"
), zone = c(2, 2, 1, 2, 2, 9, 8, 7, 6, 5, 2, 2, 6, 4, 9,
9, 5, 6, 5, 9, 8, 6), des = c("Edward Olivares grounds out, second baseman Gleyber Torres to first baseman Anthony Rizzo.",
"Bobby Witt Jr. singles on a sharp line drive to center fielder Aaron Hicks.",
"Bobby Witt Jr. flies out to right fielder Giancarlo Stanton.",
"Oscar Mercado pops out to first baseman Anthony Rizzo in foul territory.",
"Owen Miller grounds out, second baseman Gleyber Torres to first baseman Anthony Rizzo.",
"Teoscar Hernandez grounds out, second baseman Gleyber Torres to first baseman Anthony Rizzo. Vladimir Guerrero Jr. to 3rd.",
"Vladimir Guerrero Jr. doubles (1) on a line drive to right fielder Aaron Judge.",
"Alejandro Kirk grounds out sharply, shortstop Isiah Kiner-Falefa to first baseman Anthony Rizzo.",
"Lourdes Gurriel Jr. grounds out sharply, second baseman Gleyber Torres to first baseman Anthony Rizzo.",
"Bo Bichette doubles (1) on a sharp line drive to center fielder Aaron Hicks.",
"Santiago Espinal flies out sharply to center fielder Aaron Hicks.",
"J.D. Martinez doubles (1) on a line drive to right fielder Aaron Judge. Xander Bogaerts scores.",
"Bobby Witt Jr. called out on strikes.", "Salvador Perez strikes out swinging.",
"Hunter Dozier called out on strikes.", "Amed Rosario called out on strikes.",
"Myles Straw strikes out on a foul tip.", "George Springer strikes out on a foul tip.",
"Matt Chapman strikes out swinging.", "Bo Bichette called out on strikes.",
"Jonathan Schoop called out on strikes.", "Miguel Cabrera called out on strikes."
), stand = c("R", "R", "R", "R", "R", "R", "R", "R", "R",
"R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R",
"R"), plate_x = c(0.07, 0.19, -0.62, 0.07, 0.24, 0.75, 0.21,
-0.42, 0.29, -0.19, -0.22, -0.2, 0.55, -0.3, 0.82, 0.46,
-0.03, 0.71, -0.24, 0.52, 0.1, 0.66), plate_z = c(3.26, 3.48,
3.08, 2.94, 2.74, 2.17, 2.01, 1.85, 2.58, 2.56, 2.75, 3.18,
2.41, 2.43, 1.75, 1.64, 2.73, 2.37, 2.34, 1.85, 1.93, 2.81
), launch_speed = c(95.9, 105.1, 86.2, 72.9, 106.7, 95.4,
91.8, 101.2, 104.2, 109.8, 100.4, 91.9, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA), launch_angle = c(-10, 15, 56, 68, 4,
-15, 9, -10, 0, 13, 36, 12, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA)), row.names = c(NA, -22L), class = c("data.table",
"data.frame"), .internal.selfref = <pointer: 0x7fbc9f01eee0>)
1条答案
按热度按时间xjreopfe1#
这里的问题是,预测值(平均值)和计数值都显示在一个调色板中。如果您为调色板定义了覆盖预测值范围的限制(我使用了
limits = c(-.1, .6)
),那么图看起来就像您期望的那样,对吗?