[R] Compact presentation of multiple figures

Richard M. Heiberger rmh at temple.edu
Mon Oct 16 00:52:31 CEST 2006


I would do something like this in lattice.  It defaults to something prettier
and gives more control if you don't want the defaults.

tmp <- data.frame(x=rnorm(120), y=rnorm(120), a=factor(rep(1:6, 20)))
xyplot(y ~ x | a, data=tmp)
xyplot(y ~ x | a, data=tmp, aspect=1, layout=c(3,2),
       scales=list(x=list(alternating=c(0,1,0)), y=list(alternating=FALSE)))


Back to regular graphics.  I misunderstood your request for a single y label.
This comes closer.  I used oma to squeeeze the two rows closer together.
I used two axis(1) statements.  The first puts the ticks on the border of
the box.  The second one puts the labels far enough away that they aren't
cluttered.  Similar adjustment is called for on the main title of each panel.

x <- rnorm(20)
y <- rnorm(20)
old.par <- par(pty = 's', xaxt = 'n', yaxt = 'n', mfrow = c(2, 3),
             mar = c(1.1, 2.1, 1.1, 0.1), oma=c(12,2,0,2))
plot(y ~ x, main=1, xlab="", ylab="")
plot(y ~ x, main=2, xlab="", ylab="")
plot(y ~ x, main=3, xlab="", ylab="")
plot(y ~ x, main=4, xlab="", ylab="")
mtext("Y label", side=2,  at=2, line=2)
plot(y ~ x, main=5, xlab="", ylab="")
axis(1, xaxt="s", labels=FALSE)
axis(1, xaxt="s", tick=FALSE, line=1)
plot(y ~ x, main=6, xlab="", ylab="")
par(old.par)



More information about the R-help mailing list