Facet grid
facet_grid()
uses a formula (y ~ x
) to lay out plots in a 2-dimensional grid. This can be useful to compare across combinations of variables.
base + facet_grid(. ~ cyl) + labs(title = ". ~ cyl")
![](bookclub-ggplot2_01_files/figure-html/unnamed-chunk-76-1.png)
base + facet_grid(drv ~ .) + labs(title = "drv ~ .")
![](bookclub-ggplot2_01_files/figure-html/unnamed-chunk-76-2.png)
base + facet_grid(drv ~ cyl) + labs(title = "drv ~ cyl")
![](bookclub-ggplot2_01_files/figure-html/unnamed-chunk-76-3.png)
Use multiple variables in the rows and columns by “adding” them: a + b ~ c + d
Variables specified on rows and columns will be crossed.
base + facet_grid(drv ~ cyl + class) + labs(title = "drv ~ cyl + class")
![](bookclub-ggplot2_01_files/figure-html/unnamed-chunk-77-1.png)