Faceting in ggplot2

Want to learn more? I recommend working through: R for Data Science, R Cookbook, and R Graphics Cookbook.

Faceting is when we show many little charts, one for each category of a factor

# load the ggplot2 library

# set the seed so we can reproduce the results
# create a plot of x = carat and y = count, with a single chart for each category of diamond color
qplot(carat, data = diamonds, facets = color ~ ., geom = "histogram", binwidth = 0.1, xlim = c(0, 3))