Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
In addition to the variables mapped to the x- and y-axes, map
another (discrete) variable to colour
or linetype, as shown in Figure 4-6:
# Load plyr so we can use ddply() to create the example data setlibrary(plyr)# Summarize the ToothGrowth datatg<-ddply(ToothGrowth,c("supp","dose"),summarise,length=mean(len))# Map supp to colourggplot(tg,aes(x=dose,y=length,colour=supp))+geom_line()# Map supp to linetypeggplot(tg,aes(x=dose,y=length,linetype=supp))+geom_line()