This section covers techniques to save and produce multiple plots. This will cover simple ways to split your graph or data into multiple plots as well as combining multiple figures into a saved image.
Facetting is the process of dividing a plot into subplots based on the values of a discrete variable. In the context of the Iris scatterplots, we can split by species across multiple plots. ggplot(iris, aes(x=Sepal.Length, y=Petal.Length)) + geom_point() + facet_grid(.~Species) As you can see, facet_grid() splits our single plot into a number of plots equal to the levels of the factor we specify. The syntax behind facet_grid() specifies our “rows” and “columns” for our plots separated by a ~ tilde.
While facetting is useful, sometimes we need to save multiple different plots into one image. There are a number of ways to accomplish this and each have their benefits. This section will only cover the “ggpubr” package. This is my personal choice for combining plots and accomplishes everything I need for publication quality figures. It should be noted that there are a plethora of packages that all accomplish a similar task (e.