Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
In the example here, we’ll specify the colors for a continuous variable using various gradient scales (Figure 12-12). The colors can be named, or they can be specified with RGB values:
library(gcookbook)# For the data set# Base plotp<-ggplot(heightweight,aes(x=ageYear,y=heightIn,colour=weightLb))+geom_point(size=3)p# With a gradient between two colorsp+scale_colour_gradient(low="black",high="white")# A gradient with a white midpointlibrary(scales)p+scale_colour_gradient2(low=muted("red"),mid="white",high=muted("blue"),midpoint=110)# A gradient of n colorsp+scale_colour_gradientn(colours=c("darkred","orange","yellow","white"))