user1723765
user1723765

Reputation: 6409

Merging plots in ggplot

I have created several plots in ggplot called stored as plot1, plot2, plot3

I would like to create a single plot where each of the plots are displayed in subplots.

Is there a way to do this?

Upvotes: 0

Views: 241

Answers (1)

Sven Hohenstein
Sven Hohenstein

Reputation: 81743

You can use grid.arrange from package gridExtra:

library(gridExtra)
grid.arrange(plot1, plot2, plot3)

An example:

library(ggplot2)
plot1 <- ggplot(mtcars, aes(mpg, cyl)) +
  geom_point()
plot2 <- ggplot(mtcars, aes(disp, hp)) +
  geom_line()
plot3 <- ggplot(mtcars, aes(vs, qsec)) +
  geom_bar(stat = "identity")

library(gridExtra)
grid.arrange(plot1, plot2, plot3)

enter image description here

Upvotes: 2

Related Questions