Skip to content
Back to formatted view

Raw Message

Message-ID: <BANLkTi=YGec4PYRF6iacmO1C_6k7XB=ojA@mail.gmail.com>
Date: 2011-04-19T02:46:50Z
From: Deepayan Sarkar
Subject: Define ylim in lattice plot based upon panel function output
In-Reply-To: <BANLkTi=eY0aasZdPODZuEZazjGnwSg9o2w@mail.gmail.com>

On Tue, Apr 19, 2011 at 7:38 AM, S?bastien Bihorel <pomchip at free.fr> wrote:
> Dear R-users,
>
> By default, the xyplot function automatically defines the axis ranges based
> upon the content of y and x variables. However, when one includes some calls
> to other panel.<something> functions in the panel argument, the results
> might be out of range and not show up in the final graphs (see lower ends of
> the loess line in the following example). Is there a way one can capture the
> results of the functions to update the graph object and set the xlim and
> ylim?

Read up on the 'prepanel' argument (in ?xyplot). What you want is
actually already defined -- see ?prepanel.loess.

xyplot(y~x,data=df,
       prepanel = prepanel.loess,
       panel=function(x,y,...){
           panel.xyplot(x,y)
           panel.loess(x,y)
       })

-Deepayan

>
> Thanks
>
> Sebastien
>
> require(lattice)
>
> df <- data.frame(x=seq(1,30,1),
> ? ? ? ? ? ? ? ? y=c(rep(0,10),rep(10,10),rep(0,10)))
>
> xyplot(y~x,data=df,
> ? ? ? panel=function(x,y,...){
> ? ? ? ? panel.xyplot(x,y)
> ? ? ? ? panel.loess(x,y)
> ? ? ? })
>
> ? ? ? ?[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>