16.1 What is faceting?

library(tidyverse)
mpg2 <- subset(mpg, cyl != 5 & drv %in% c("4", "f") & class != "2seater")

Faceting breaks down a dataset into multiple plots that show different subsets of the data, often plotting the same variables in each plot.

There are three types of faceting functions:

  • facet_null(): a single plot, the default
  • facet_wrap(): “wraps” a 1d ribbon of panels into 2d
  • facet_grid(): produces a 2d grid of panels defined by variables which form the rows and columns