[R] request for fine panel axis controls in lattice

Deepayan Sarkar deepayan.sarkar at gmail.com
Tue Aug 5 18:40:43 CEST 2008


On 8/5/08, Chuck Cleland <ccleland at optonline.net> wrote:
> On 8/5/2008 8:37 AM, Chosid, David (FWE) wrote:
>
> > I'm trying to use fine axis controls in lattice for each panel.
> > Specifically, within each panel, I want to set the limits for x and y
> > equal to each other since it is paired data (using the max value of the
> > two).  Of course, I have no problems setting the limits for the entire
> > plot but I am having trouble setting them for each specific panel.
> > Could someone please provide me some guidance?  Thanks in advance.
> >
>
>   Here is an example with panel-specific limits:
>
>  library(lattice)
>
>  xyplot(Sepal.Length ~ Petal.Length | Species, data = iris, layout=c(3,1,1),
>        ylim=as.data.frame(matrix(c(1,3,4.5,5.8,7,7.9),
> byrow=TRUE, nrow=2)),
>        xlim=as.data.frame(matrix(c(1,3,4.5,5.8,7,7.9),
> byrow=TRUE, nrow=2)),
>        scales=list(x=list(relation="free"),
>                    y=list(relation="free")))

A more elegant approach is to use a prepanel function:

xyplot(..., scales = "free", aspect = "iso",
       prepanel = function(x, y, ...) {
           rng <- range(x, y, finite = TRUE)
           list(xlim = rng, ylim = rng)
       })

-Deepayan



More information about the R-help mailing list