## 2.5 Faceting / paneling

This is a good place to introduce a term called faceting. The definition is a particular aspect or feature of something, or one side of something many-sided, especially of a cut gem. Basically instead of plotting the grouped graphics on the same plotting area, we let each group have it’s own plot, or facet.

We add a facet_wrap() and specify that we want to panel on the color group. Note the twiddle in front of color.

ggplot(dsmall, aes(x=carat, fill=color)) + geom_density() + facet_wrap(~color)

The grid placement can be semi-controlled by using the ncol argument in the facet_wrap() statement.

ggplot(dsmall, aes(x=carat, fill=color)) + geom_density() + facet_wrap(~color, ncol=4)

It is important to compare distributions across groups on the same scale, and our eyes can compare items vertically better than horizontally. So let’s force ncol=1.

ggplot(dsmall, aes(x=carat, fill=color)) + geom_density() + facet_wrap(~color, ncol=1)