[R] plot order in multi-panel figure
Greg Snow
Greg.Snow at imail.org
Fri Sep 19 21:21:16 CEST 2008
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
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Stephen Tucker
> Sent: Friday, September 19, 2008 8:37 AM
> To: R-help
> Subject: [R] plot order in multi-panel figure
>
> 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
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list