[R] shared axes in multipanel plot

Jennifer Young Jennifer.Young at math.mcmaster.ca
Fri Dec 11 16:02:47 CET 2009


Hello

I've created a function to make a plot with multiple pannels from columns
of data that are created in a previous function.  In the example below the
number of columns is 8, giving 4 pannels, but in general it takes data
with any number of columns and figures out a nice layout.

The panels all have the same axes, and so I wonder what functions are
avialable to create axes only on the left and bottom of the whole plot
rather than each pannel.
I'd really like a generic way to do this for any number of plots, but was
even having trouble figuring out how to do it manually for this example;
How are pannels referred to, in a layout context?
That is, how do I say,

if(current.pannel==4) {do stuff}

Here's a simple version of the code.

baseline <- (1:20)/20    #example data
dat1 <- matrix(baseline,20,8)
dat <- dat1+matrix(rnorm(20*8)/30, 20,8)

nstrat <- ncol(dat)
rows <- ceiling(nstrat/4)
layout(matrix(1:(rows*2), rows, 2, T))
par(oma=c(4,4,3,1))
par(mar=c(1,1,0,1))
for(i in which(1:nstrat%%2!=0)){
    plot(baseline, type="l", col="grey", lwd=2,
            xlab="", ylab="", ylim=c(0,1), xaxt='n', yaxt='n')
    axis(1, labels=F); axis(2, labels=F)
    points(dat[,i], type="l", lty=2)
    points(dat[,i+1], type="l", lty=2)
}



Thank you muchly
Jennifer Young

PS: I am a subscriber, but can't for the life of me figure out how to send
an email while logged in so that the moderators don't have to take the
time to read it over.  I always get the "please wait while we check it
over" email.  Likely I'm being dumb.




More information about the R-help mailing list