# How to plot multiple loess curves in a xyplot panel data?

Imagine the following simplified longitudinal data with 4 individuals and 3 variables (y1, y2, y3) measured at 50 occasions :

dat<-data.frame(subject=as.factor(rep(1:4, each=50)),time=rep(1:50,4),y1=rnorm(200,50,20),y2=rnorm(200,70,20),y3=rnorm(200,20,20))


It is easy to plot at the same time the raw time series with this code :

xyplot(y1+y2+y3~time|subject,dat,type='l')


which result is : I would like to plot exactly the same, but with loess curves instead of lines. And here is my problem! The following code :

xyplot(y1+y2+y3~time|subject,dat,
panel=function(x,y)
{panel.loess(x,y,span=0.2)
})


doesn't work because it considers y1+y2+y3 as a single variable, thus plotting only one loess curve by panel. How is it possible to plot each loess curve in each panel?

PS. I don't want to use type="smooth" because I need to specify the span of the loess.

Use type='smooth' instead of type='l':
xyplot(y1+y2+y3~time|subject,dat,type='smooth')

• Big ooops!!! It is indeed simple. I didn't know it was possible to change span of smooth. It works well with this code : xyplot(y1+y2+y3~time|subject,dat,type='smooth',span=.3) My question is perhaps not very useful after all. Perhaps it is better to delete it? Let me know. Oct 13, 2011 at 16:54