Wider margins for grid.arrange function

R18 picture R18 · May 24, 2017 · Viewed 7.7k times · Source

I'm building a composition of plots (created using ggplot2) running the function grid.arrange. Although I have the composition done, I want the plots not to be so close to the margins.

I know for other type of plots, the function par() allows to modify these distances, but how can I do this for a composition with grid.arrange()?

Answer

baptiste picture baptiste · May 24, 2017

you can change the plot margins,

pl = replicate(5, ggplot(), FALSE)

grid.arrange(grobs = pl) # default margins
# vs
grid.arrange(grobs= lapply(pl, "+", theme(plot.margin=margin(10,10,10,10))))

enter image description here

Edit: if the intent is to have the plots away from the device's borders, then one should draw in a reduced viewport,

grid.arrange(grobs = pl, vp=viewport(width=0.7, height=0.7))

enter image description here