[R] identical scales per panel with relation="free"

Andreas Krause andreas at elmo.ch
Wed Apr 16 14:00:03 CEST 2008


Using xyplot, I am plotting observed versus predicted values conditional to the values of a third variable.
I would thus like to have an aspect ratio of 1 and the same axis range.
Since the range of the values differs substantially between panels, the axis ranges shall be different for each panel (along the lines of relation="free"). However, x- and y-limits shall still be the same for a given panel.
Any ideas on how to achieve that?

# Example (that produces different x/y-limits per panel)
set.seed(3484)
x <- data.frame(
    "x"=c(rnorm(10), rnorm(10, 10))
)
x$y <- x$x + rnorm(length(x$x))
x$z <- c(rep(c("A", "B"), c(10, 10)))

print(xyplot(y ~ x | z, data=x,
    aspect=1,
    scales=list(
        relation="free"
    ),
    panel=function(x, y, ...)
    {
        panel.abline(0, 1)
        panel.xyplot(x, y, ...)
    }
))



More information about the R-help mailing list