1
votes

I would like to arrange multiple plots into one figure, without any gaps between the plot area, and all plots being exactly the same size (see image below for a sketch of my desired figure, which comprises 6 individual plots).

desired figure, composed of 6 individual plots

I have tried ggarrange (ggpubr) and plot_grid (cowplot) and a couple others but they seem to have the same problem - you can align the plots to get them the same size, but not arrange them closer to each other.

ggdraw in the cowplot package allows one to specify exactly where the plots go, but they are all slightly different sizes.

Is there a way to overcome this?

Basically, I want to make the plot area (where the data is displayed, NOT the axes and labels) the same for six graphs, then arrange them contiguously. So far I have not found anyway to do this.

The x-axis variable is the same for all 6 graphs, but the y is different, and there are multiple series on some of the graphs but not others, so I cannot use the facet option in ggplot2.

Please help!

EDIT: Sorry, some more info - because my plots have different y variables, the plot margins and the plot panels are all slightly different sizes. So that means when I try to add them all together, they are out of alignment. Plots different sizes out of alignment. plot_grid from cowplot allows you to specify position, and size, BUT, the size is the size of the whole plot, panel and margins included. Because of the Y-axis labels, the margins are different sizes, and resizing them using the arguments to plot_grid is not so simple.

1
Have you seen these questions? Unsure if they're duplicates, but they might help: reduce space between grid.arrange plots, and Side-by-side plots with ggplot2divibisan
cowplot::draw_plot lets you specify position, height and width.pogibas
I use library(gridExtra) to combine plots - works perfectly. Specify layout <- rbind(c(1, 1, 1), c(2, 2, 2)) and use grid.arrange(p1, p2, layout_matrix = layout) AND for p1 and p2 (two ggplots) add theme(plot.margin=unit(c(0,0,0,0),"cm")) to control space between two plotsAnnaZ
Possible duplicate of Side-by-side plots with ggplot2divibisan
Thank you for your responses. None of the options were quite what I was looking for: stackoverflow.com/questions/1249548/… still leaves some gaps between the plots, and I need the gaps gone completely. This one stackoverflow.com/questions/13299496/… I don't even understand how to use, being relatively new to R.S.T.

1 Answers

1
votes

So I managed to find an answer, based on some code from here: https://community.rstudio.com/t/how-do-i-control-the-size-of-the-panel-in-a-ggplot-so-they-are-consistent/14377/8

The plots first need to be passed through the align_plots() function in cowplot() , to make a list of the plots:

`multiplot <- align_plots(plotAA,plotBB,plotCC,plotDD,plotEE,plotFF, align = "hv")`    

Then the panels of the graphs will be all the same size, and they can be arranged using ggdraw() and draw_plot() as follows:

`ggdraw() + draw_grob(multiplot[[1]], 0,0.565,.6,.4) +
  draw_grob(multiplot[[2]], 0.396,0.565,0.6,0.4) + 
  draw_grob(multiplot[[3]], 0, 0.285, 0.6,0.4) +
  draw_grob(multiplot[[4]], 0.396, 0.285, 0.6, 0.4) +
  draw_grob(multiplot[[5]], 0,0.004, 0.6, 0.4) +
  draw_grob(multiplot[[6]], 0.396,0.004,0.6,0.4)`

to give the final figure: Desired plot arrangement

I hope this helps somebody else in the future, Thanks.