I am attempting to make a map of global data anomaly (precip, temp etc) and need to use a diverging color palette. I have code that runs well with scale_color_viridis
but it does not easily convert with scale_color_brewer
. I would like to use the RdBu
diverging palette.
I have tried supplying the values vars
within the function scale_color_brewer
and using scale_fill
brewer but I would like to continue plotting using the geom_points
I have so far.
titletext <- paste(VAR, "Response")
expand.grid(lon, lat) %>%
rename(lon = Var1, lat = Var2) %>%
mutate(lon = ifelse(lon > 180, -(360 - lon), lon),
vars = as.vector(global.array)) %>%
ggplot() +
geom_point(aes(x = lon, y = lat, color = vars),
size = 2.0) +
borders("world", colour="black", fill=NA) +
scale_color_brewer(type="div", palette="RdBu")+
#scale_color_viridis(na.value="white",name = VAR) +
theme(legend.direction="vertical", legend.position="right",
legend.key.width=unit(0.4,"cm"), legend.key.heigh=unit(2,"cm")) +
coord_quickmap() + ggtitle(titletext)
Error message is
Error: Continuous value supplied to discrete scale
and
Warning messages: 1: In RColorBrewer::brewer.pal(n, pal) : n too large, allowed maximum for palette RdBu is 11 Returning the palette you asked for with that many colors
scale_*_distiller()
is what you want. – Bergama