[R] xyplot

David Barron mothsailor at googlemail.com
Fri Oct 6 00:57:51 CEST 2006


If you include a conditioning factor (here it is the variable
"groups") you will get more than one panel. To get loess curves for
the two groups, the easiest way is to use the type argument:

> xyplot(y ~ time, groups=group,data=df,type=c("p","smooth"))


On 05/10/06, Osman Al-Radi <osman.al.radi at gmail.com> wrote:
> Hello,
>
> Thanks for your answer, however, the resulting graph has two panels with a
> loess curve per subject. I need a single panel with a loess curve per
> group..
>
> Osman
>
> On 10/5/06, Sundar Dorai-Raj <sundar.dorai-raj at pdf.com> wrote:
> >
> >
> >
> > Osman Al-Radi said the following on 10/5/2006 3:43 PM:
> > > Hi,
> > >
> > > for the data below:
> > > time<-c(rep(1:10,5))
> > > y<-time+rnorm(50,5,2)
> > > subject<-c(rep('a',10),rep('b',10),rep('c',10),rep('d',10),rep('e',10))
> > > group<-c(rep('A',30),rep('B',20))
> > > df<-data.frame(subject,group,time,y)
> > >
> > > I'd like to produce a plot with a single pannel with two loess curves
> > one
> > > for each group. the code below does that but on two different pannels,
> > I'd
> > > like to have both curves on the same pannel with different colors.
> > >
> > > xyplot(y~time|group, groups=subject,
> > >     panel=function(...){
> > >         panel.loess(...)
> > >         }
> > >     ,data=df)
> > >
> > >
> >
> > Simple:
> >
> > xyplot(y ~ time | group, data = df, groups = subject,
> >         panel = function(...) {
> >           panel.superpose(...)
> >           panel.superpose(panel.groups = panel.loess, ...)
> >         })
> >
> > HTH,
> >
> > --sundar
> >
>
>
>
> --
> Osman O. Al-Radi, MD, MSc, FRCSC
> Fellow, Cardiovascular Surgery
> The Hospital for Sick Children
> University of Toronto, Canada
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>


-- 
=================================
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP



More information about the R-help mailing list