I am trying to make something similar to the Percentile Ranking on Baseball Savant but I can't get the color change to work. Currently the ggplot correctly ranks hitters based on their max exit velocity but the points color always gets stuck on the "mid" color regardless of the location of the point.
test_df <- data.frame(
Batter = c("Player 1", "Player 2", "Player 3", "Player 4"),
MaxExitVelo = c(105, 107, 102, 108),
rank = c(1, 2, 3, 4)
)
test_df %>%
filter(Batter == "Player 2") %>% #Manually change Batter name to calculate ranking
ggplot(aes(x = rank, y = "")) +
geom_point(size = 10, aes(color = rank)) +
geom_text(aes(label = rank)) +
geom_label(aes(label = round(MaxExitVelo, digits = 1)), nudge_x = 0, nudge_y = 0.15) +
ggtitle("Max Exit Velocity") +
scale_x_reverse(expand = c(0,0.5), limits = c(max_rank + 1, 0)) +
scale_color_gradient2(low = "blue", mid = "white", high = "red") +
theme_linedraw(base_line_size = 5) +
theme(legend.position = "none",
panel.border = element_rect(color = "white"),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_blank(),
axis.title.y = element_blank(),
axis.ticks.x = element_blank(),
axis.text.x = element_blank(),
axis.title.x = element_blank(),
plot.title = element_text(hjust = 0.5, vjust = -15)
)