jlwoodard <john.woodard <at> wayne.edu> writes:

> 
> 
> I'm trying to understand how to plot individual growth curve trajectories,
> with the overall mean trajectory superimposed (preferably in a slightly
> thicker line, maybe in black) over the individual trajectories.  Using the
> sleepstudy data in lme4, here is the code I have so far:
> 
> library(lme4)
> library(lattice) 
> xyplot(Reaction ~ Days, data = sleepstudy, group = Subject, type = 'l')
> 
> This plot produces the individual growth curves nicely, but I'd like to be
> able to plot the mean for each day (averaged over subjects) on top of this
> graph.
 
Is this what you want?

xyplot(Reaction ~ Days, data = sleepstudy, group = Subject, type = 'l',
panel=function(...){
  panel.xyplot(...)
  panel.average(...,fun=mean,horizontal=FALSE,col='red',lwd=3)
    }
  )

and have you considered:

xyplot(Reaction ~ Days, data = sleepstudy, group = Subject, type = 'l',
panel=function(...){
  panel.xyplot(...)
  panel.loess(...,fun=mean,horizontal=FALSE,col='red',lwd=3)
    }
  )

for a smoother curve?



Hope it helps,

Michael Bibo
Queensland Health

______________________________________________
R-help@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.

Reply via email to