[R] shared axes in multipanel plot

Jennifer Young Jennifer.Young at math.mcmaster.ca
Mon Dec 14 21:19:13 CET 2009


> On Mon, Dec 14, 2009 at 11:30 AM, Jennifer Young
> <Jennifer.Young at math.mcmaster.ca> wrote:
>> splendid!
>>
>> This worked well, but there are two oddities that I can't resolve.
>>
>> 1. In the real data, the "baseline" is a cumulative probability plot
>> (from
>> simulations) rather than the straight line.  The panel.lines plots this
>> curve, but seems to join the first and last points together.
>> panel.points(x, baseline, type="l") did the same.
>> I checked that the vector is indeed sorted properly, so I'm not sure why
>> it should connect the first point to the last.
>
> I can't reproduce the problem based on this description.

sorry that was lazy of me. If you modify the code you gave me as follows
(with an extra line of the sqare root of "baseline", as an example) the
first and last points are joined. I didn't notice this before when
"baseline" was just a line.

baseline <- (1:20)/20
dat1 <- matrix(baseline,20,8)
dat <- dat1+matrix(rnorm(20*8)/30, 20,8)
b2<-sqrt(baseline)
pnl <- function(x, ...) {
        panel.plot.default(x, ...)
        panel.lines(x, baseline, lwd = 2, col = grey(0.5))
        panel.lines(x, b2)
}
nc <- ncol(dat)
screens <- rep(1:(nc/2), each = 2)
z <- zoo(dat)
colnames(z) <- paste("Group", screens)
xyplot(z, screens = screens , layout = c(2, 2), col = "black", lty =
2, scales = list(y = list(relation = "same")), panel = pnl)


>
>>
>> 2. The screens are correctly labeled, but in the wrong order (left to
>> right, top to bottom: 3,4,1,2). Is this easily corrected?
>
> xyplot(..., as.table = TRUE) will give one reordering.
>
> Another possibility is:
>    plt <- xplot(...)
>    plt[ix]
> where ix is a permutation of 1:4
>
>>

as.table=TRUE did the trick thanks.




More information about the R-help mailing list