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


Categories: Research
Tags: , ,
  • lola


  • pietrop

    Thank you!

  • ScottRobinett


  • Super John

    Thanks for this awesome resource! My follow up question is how did you get those legends in the chart space?

  • Nitish


  • Gandalf

    it says cant find grid.arrange. I installed the grid extra package.

  • Gandalf

    Nevermind I had to add library(gridExtra). Sorry im a noob.

    • Santi L

      add these two lines before using grid.arrange.