Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Use facet_grid() or facet_wrap(), and specify the variables on which to split.
With facet_grid(), you can
specify a variable to split the data into vertical subpanels, and
another variable to split it into horizontal subpanels (Figure 11-1):
# The base plotp<-ggplot(mpg,aes(x=displ,y=hwy))+geom_point()# Faceted by drv, in vertically arranged subpanelsp+facet_grid(drv ~.)# Faceted by cyl, in horizontally arranged subpanelsp+facet_grid(.~ cyl)# Split by drv (vertical) and cyl (horizontal)p+facet_grid(drv ~ cyl)