Add extra spacing between a subset of plots

chrisamiller picture chrisamiller · Sep 3, 2010 · Viewed 13.2k times · Source

I'm trying to output 6 figures into one image, in a 3x2 layout. I'd like to place extra space between the top row and the bottom two rows. Is this possible using R? I've looked through the documentation for par and plot and can't seem to find an appropriate option.

Here's some example code:

a = rnorm(100,100,10)
b = rnorm(100,100,10)

par(mfrow=c(3,2), oma=c(1,1,1,1), mar=c(2,2,2,2))
hist(a)
hist(b)
plot(a,b)
plot(a,b)
plot(a,b)
plot(a,b)

Here's what that code outputs:


alt text


Here's what I'd like it to output (I modified this image in an external editor). Note the extra space between the top row and bottom rows.


alt text


Answer

nico picture nico · Sep 3, 2010

I can think of three ways:

1) Use the mar graphic parameter to set plot margin

You can retrieve current margins with

currmar <- par()$mar

You can set new margins with

par("mar"=c(5, 4, 4, 2))

with the for numbers being bottom, left, top and right margins (see ?par)

You can make multiple calls to par for each plot, so you can change the bottom margin only for the top plots.

2) Use layout to generate an uneven layout grid (see ?layout for examples)

3) Save the plot in .svg or .pdf and then use Inkscape (or whatever software you like) to move the plots.