ggplot2 – Multiple Plots in One Graph Using gridExtra

I’ve been using ggplot2’s facet_wrap and facet_grid feature mostly because multiplots I’ve had to plot thus far were in one way or the other related. However, I needed to plot a multiplot consisting of four (4) distinct plot datasets. In the past, when working with R base graphics, I used the layout() function to achive this [1].
A quick search online initially resulted in this [2] tutorial that involves creating a new function; and interesting these [3, 4] blog posts that propose using the gridExtra package [5].

Install gridExtra


Generate individual plots and arrange in grid

# define individual plots
p1 = ggplot(...)
p2 = ggplot(...)
p3 = ggplot(...)
p4 = ggplot(...)
# arrange plots in grid
grid.arrange(p1, p2, p3, p4, ncol=2)

Sample output is below.

gridExtra Sample
gridExtra Sample