## 2.5 Faceting

Another technique for displaying additional categorical variables on a plot is faceting. Faceting creates tables of graphics by splitting the data into subsets and displaying the same graph for each subset. You’ll learn more about faceting in Section 16, but it’s such a useful technique that you need to know it right away.

There are two types of faceting: grid and wrapped. Wrapped is the most useful, so we’ll discuss it here, and you can learn about grid faceting later. To facet a plot you simply add a faceting specification with facet_wrap(), which takes the name of a variable preceded by ~.

ggplot(mpg, aes(displ, hwy)) +
geom_point() +
facet_wrap(~class)

1. What happens if you try to facet by a continuous variable like hwy? What about cyl? What’s the key difference?
3. Read the documentation for facet_wrap(). What arguments can you use to control how many rows and columns appear in the output?
4. What does the scales argument to facet_wrap() do? When might you use it?