Re: [R] complex plots using layout()

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Fri 29 Sep 2006 - 12:24:10 GMT

Lu, Jiang Jane wrote:
> Dear r-help,
>
> I am trying to plot several scatter plots with marginal histograms on
> one page. Ideally, a page is equally divided into 4 figure regions.
> Within each figure region, a scatter plot with marginal histograms will
> be plotted.
>
> I followed Dr. Paul Murrell's code released online to successfully plot
> the scatter plot with marginal histograms. The code applies "layout()"
> to partition the page.
>
> Right now, I want each of the 4 figure regions on one page to be plotted
> a scatter plot with marginal histograms. I tried par(mfrow= ) ahead of
> layout(). It does not work. Could I repeat layout() to reach my point?

No, nested layout(), par(mfrow) and theirlike are not supported, but there is the other R graphics system in package grid which supports stuff like that extraordinary well. See For example Paul's book on "R Graphics".

Uwe Ligges

> Following is the code I use. Any advice is greatly appreciated.
>
> =================================================================
> x <- demog$age
> y1 <- demog$mji
> y2 <- demog$nles
> xhist <- hist(x, plot=FALSE)
> y1hist <- hist(y1, plot=FALSE)
> y2hist <- hist(y2, plot=FALSE)
>
> top1 <- max(c(xhist$counts, y1hist$counts))
> top2 <- max(c(xhist$counts, y2hist$counts))
>
> xrange <- range(x,na.rm=TRUE)
> y1range <- range(y1,na.rm=TRUE)
> y2range <- range(y2,na.rm=TRUE)
>
> def.par <- par(no.readonly = TRUE)
>
> par(mfrow=c(2,2))
>
> nf <- layout(matrix(c(2,0,1,3),2,2,byrow=TRUE), c(3,1), c(1,3), TRUE)
>
> par(mar=c(3,3,1,1))
> plot(x, y1, xlim=xrange, ylim=y1range, xlab="Age", ylab="MJI")
> lines(lowess(x,y1),col=2)
> par(mar=c(0,3,1,1))
> barplot(xhist$counts, axes=FALSE, ylim=c(0, top1), space=0)
> par(mar=c(3,0,1,1))
> barplot(y1hist$counts, axes=FALSE, xlim=c(0, top1), space=0, horiz=TRUE)
>
> par(mar=c(3,3,1,1))
> plot(x, y2, xlim=xrange, ylim=y2range, xlab="Age", ylab="Numer of
> Lesions")
> lines(lowess(x,y2),col=2)
> par(mar=c(0,3,1,1))
> barplot(xhist$counts, axes=FALSE, ylim=c(0, top2), space=0)
> par(mar=c(3,0,1,1))
> barplot(y2hist$counts, axes=FALSE, xlim=c(0, top2), space=0, horiz=TRUE)
>
>
> par(def.par)
>
> ================================================================
>
>
> Sincerely yours,
>
> Jiang Lu
>
> Statistician
>
> University of Pittsburgh
> 130 DeSoto Street, 127 Parran Hall
> Pittsburgh, PA 15261
> USA
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.



R-help@stat.math.ethz.ch 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. Received on Fri Sep 29 22:29:39 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 29 Sep 2006 - 13:30:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.