Home > database >  Arranging multiple ggplots in the plot window
Arranging multiple ggplots in the plot window

Time:06-03

I have multiple ggplots and want to arrange them in the plot window in a rectangular fashion. Below is my code

library(ggplot2)
library(ggpubr)
plot1 = ggplot(data.frame(x = 1:3, y = 4:6), aes(x = x, y = y))   geom_line()
plot2 = ggplot(data.frame(x = 1:3, y = 4:6), aes(x = x, y = y))   geom_line()
plot3 = ggplot(data.frame(x = 1:3, y = 4:6), aes(x = x, y = y))   geom_line()
ggarrange(plot1, plot2, plot3, ncol = 2, nrow = 2, align = 'h')

I am getting below arrangement

enter image description here

I am wondering if the 3rd plot can be placed in the middle of the plot window?

Any pointer will be very helpful.

CodePudding user response:

library(patchwork)
design <- 
  "1122
   1122
   #33#
   #33#"
plot1   plot2   plot3   plot_layout(design = design)

enter image description here

CodePudding user response:

I adapted code from enter image description here

Or

wrap_plots(A = plot1, B = plot2, C = plot3, design = "AABB\n#CC#")

enter image description here

  • Related