[R] complex plots using layout()
Uwe Ligges
ligges at statistik.uni-dortmund.de
Fri Sep 29 14:24:10 CEST 2006
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 at 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.
More information about the R-help
mailing list