[R] plotting groupedData object

Deepayan Sarkar deepayan.sarkar at gmail.com
Tue May 2 06:52:58 CEST 2006


On 5/1/06, Osman Al-Radi <osman.al.radi at gmail.com> wrote:
> thank your help, here is a simulated data set
>
> 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)
> gd<-groupedData(y~time|subject,outer=~group,data=df)
> plot(gd,outer=T)
>
> this produces 2 panels with two lines for group=B, and 3 lines for
> group=A. Is there a way to add another line to each panel representing
> the mean at each time point or a lowess curve?

Do you mean ignoring the grouping? That's easier to do if you use
xyplot directly (which the plot method ultimately calls), e.g.:

xyplot(y ~ time | group, df, groups = subject, type = 'b',
       auto.key = list(lines = TRUE, points = FALSE, columns = 5),
       panel = function(...) {
           panel.linejoin(..., horizontal = FALSE, col = 'black')
           panel.superpose(...)
       })

xyplot(y ~ time | group, df, groups = subject, type = 'b',
       auto.key = list(lines = TRUE, points = FALSE, columns = 5),
       panel = function(...) {
           panel.loess(..., col = 'black')
           panel.superpose(...)
       })

-Deepayan




More information about the R-help mailing list