[R] complex plots using layout()
Paul Murrell
p.murrell at auckland.ac.nz
Wed Oct 4 02:50:15 CEST 2006
Hi
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?
>
> Following is the code I use. Any advice is greatly appreciated.
You could just repeat the initial layout four times (untested because I
could not run your code sample because I do no have 'demog') ...
layout(matrix(c(2,0,5,0,1,3,4,6,8,0,11,0,7,9,10,12), 4, 4, byrow=TRUE),
c(3,1,3,1), c(1,3,1,3), TRUE)
... adding extra (zero-ed) columns/rows to allow for empty space between
plots as necessary.
Paul
> =================================================================
> 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.
--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/
More information about the R-help
mailing list