[R] Mean and individual growth curve trajectories
Michael Bibo
michael_bibo at health.qld.gov.au
Mon Nov 1 04:10:05 CET 2010
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
More information about the R-help
mailing list