And just in case anyone wants to know how to do it from scratch in grid...
library(ggplot2)
library(dplyr)
library(grid)
vps <- c("top_left", "top_mid", "top_right", "bottom_left", "bottom_right")
main_vp <- vpTree(viewport(name = "main"), vpList(
viewport(x = 1/6, y = 0.75, width = 1/3, height = 0.5, name = vps[1]),
viewport(x = 3/6, y = 0.75, width = 1/3, height = 0.5, name = vps[2]),
viewport(x = 5/6, y = 0.75, width = 1/3, height = 0.5, name = vps[3]),
viewport(x = 1/3, y = 0.25, width = 1/3, height = 0.5, name = vps[4]),
viewport(x = 2/3, y = 0.25, width = 1/3, height = 0.5, name = vps[5])))
grid.newpage()
pushViewport(main_vp)
plots <- lapply(1:5, function(i){
seekViewport(vps[i])
invisible(grid.draw(ggplotGrob(
ggplot(filter(airquality, Month == levels(as.factor(airquality$Month))[i]),
mapping = aes(Day, Temp)) +
geom_line() +
facet_grid(.~Month)
)))})
Created on 2020-07-03 by the reprex package (v0.3.0)
facet_grid
– Commonality