Skip to content

plot order in multi-panel figure

3 messages · Satoshi Takahama, Mark Lyman, Greg Snow

#
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
#
Stephen Tucker <brown_emu <at> yahoo.com> writes:
traditional graphics device?
(2,1)) but with underlying grid
Below is one approach using split.screen. See ?split.screen for details.
[1] 1
[1] 2 3
[1] 1 2 3

Mark Lyman
#
You can reset the figure number with the 'mfg' parameter to 'par', but to do what you want you may be able to do using other tools.  Look at the examples for the cnvrt.coords function in the TeachingDemos package (you can do similar things with the grconvertX and grconvertY functions) or look at the subplot function in the TeachingDemos package for another possible approach.

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111