9

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()?

zx8754
  • 52,746
  • 12
  • 114
  • 209
R18
  • 1,476
  • 1
  • 8
  • 17
  • [Change "plot.margin"](https://stackoverflow.com/questions/15556068/removing-all-the-space-between-two-ggplots-combined-with-grid-arrange) for your individual plots. – Adam Quek May 24 '17 at 07:47

1 Answers1

16

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

baptiste
  • 75,767
  • 19
  • 198
  • 294