How to make a continuous ggplot2 scale with midpoint 10, min 0 and max 20?
I am able to get the midpoint of 10, but I wasn't sure how to do the rest. It seems like the rescaler argument and the scales::rescale functions are the way to do this??
library(tidyverse)
mpg %>%
mutate(centred = cty - mean(cty)) %>% #
select(displ, hwy, centred) %>%
ggplot() +
geom_point(aes(x = displ, y = hwy, col = centred)) +
scale_color_gradientn(
colors = c("red", "white", "blue"),
rescaler = ~scales::rescale_mid(.x, mid = 10),
breaks = scales::breaks_width(4))
Created on 2023-06-18 with reprex v2.0.2