Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wider margins for grid.arrange function

Tags:

r

ggplot2

r-grid

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

like image 918
R18 Avatar asked May 24 '17 07:05

R18


1 Answers

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

like image 118
baptiste Avatar answered Sep 21 '22 19:09

baptiste