3
The options facet_wrap()
and facet_grid()
in the ggplot
have similar purposes, produce graphs with results stratified by a categorical variable. However, sometimes these options produce aesthetically identical results, sometimes similar, sometimes very different.
What is the difference in rationality behind these two options? Is there any criterion for choosing one of the two?
Example of identical result:
library(ggplot2)
g1 <- ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
geom_point()
g1 + facet_wrap(~ Species)
g1 + facet_grid(~ Species)
Example of similar result:
g2 <- ggplot(mpg, aes(displ, hwy)) +
geom_point()
g2 + facet_wrap(~cyl)
g2 + facet_grid(~cyl)
Example of different result:
g2 <- ggplot(mpg, aes(displ, hwy)) +
geom_point()
g2 + facet_wrap(cyl~class)
g2 + facet_grid(cyl~class)