3
$\begingroup$

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 :

enter image description here

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.

$\endgroup$

1 Answer 1

4
$\begingroup$

Use type='smooth' instead of type='l':

xyplot(y1+y2+y3~time|subject,dat,type='smooth')
$\endgroup$
3
  • $\begingroup$ Thanks for your answer but as I mentioned in my post, I can't use type="smooth" because I need to specify the span of the loess. Is it possible to change the parameter of 'smooth'? $\endgroup$
    – maxTC
    Oct 13, 2011 at 16:37
  • 3
    $\begingroup$ 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. $\endgroup$
    – maxTC
    Oct 13, 2011 at 16:54
  • $\begingroup$ @maxTC Nope. It will probably be useful for future users sharing the same concern. $\endgroup$
    – chl
    Oct 14, 2011 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.