I have another post in my ggplot2 series, this time covering facets:
Notice that we create a graph per continent by setting
facets = ~continent
. The tilde there is important—it’s a one-sided formula. You could also writec("continent")
if that’s clearer to you.I also set the number of columns, guaranteeing that we see no more than 3 columns of grids. I could alternatively set
nrow
, which would guarantee we see no more than a certain number of rows.There are a couple other interesting features in facet_wrap. First, we can set
scales = "free"
if we want to draw each grid as if the others did not exist. By default, we use a scale of “fixed” to ensure that everything plots on the same scale. I prefer that for this exercise because it lets us more easily see those continental clusters.
Facets let you compare multiple graphs quickly. They’re great for fast comparison, but as I show in the post, you can distort the way the data looks by lining it up horizontally or vertically.