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

From: Deepayan Sarkar <deepayan.sarkar_at_gmail.com>
Date: Wed, 16 Apr 2008 07:55:27 -0700

On 4/16/08, Andreas Krause <andreas_at_elmo.ch> wrote:
>
> 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, ...)
> }
> ))

Try this:

print(xyplot(y ~ x | z, data=x,

   aspect=1,
   scales=list(

       relation="free"
   ),
   prepanel = function(x, y, ...) {

       r <- range(x, y, ...)
       list(xlim = r, ylim = r)

   },
   panel=function(x, y, ...)
   {
       panel.abline(0, 1)
       panel.xyplot(x, y, ...)

   }
))

-Deepayan



R-help_at_r-project.org 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. Received on Wed 16 Apr 2008 - 15:16:32 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 16 Apr 2008 - 16:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive