[R] plot order in multi-panel figure

Stephen Tucker brown_emu at yahoo.com
Fri Sep 19 16:36:41 CEST 2008


Hi, 

Does anyone know if there is a way to 'reset the plot number' on a traditional graphics device?

For instance, I want to have two plots on stacked top of each other (mfrow=c(2,1)) but with underlying grid lines spanning both figures vertically. I can put the grid lines on top if I add them last:

par(mfrow=c(2,1))
plot.new()
plot.window(c(0,1),c(0,1))
for( i in 1:2) axis(i)
box(bty="L")
rect(0.2,0.2,0.5,0.5,col=8)

plot.new()
plot.window(c(0,1),c(0,1))
for( i in 1:2) axis(i)
box(bty="L")

par(mfrow=c(1,1))
plot.window(c(0,1),c(0,1))
abline(v=seq(0,1,by=0.2),lty=3)

But ideally I would like to draw the grid lines before drawing other objects on top of it, but something like

par(mfrow=c(1,1))
plot.new()
plot.window(c(0,1),c(0,1))
abline(v=seq(0,1,by=0.2),lty=3)

par(mfrow=c(2,1))
plot.window(c(0,1),c(0,1))
for( i in 1:2) axis(i)
box(bty="L")
rect(0.2,0.2,0.5,0.5,col=8)

plot.new()
plot.window(c(0,1),c(0,1))
for( i in 1:2) axis(i)
box(bty="L")

does not work because the first of the two plots appears in the bottom of the figure and not the top (as it is interpreted as the second of the mfrow=c(2,1) plots). I've also played around with layout() but I also get the same behavior.

I suspect I can do this eventually with grid graphics but was wondering if it is also possible in traditional graphics. I would appreciate any help - thanks very much!
Stephen



More information about the R-help mailing list