[R] plot spaghetti data
Douglas Bates
dmbates at gmail.com
Sun Sep 18 18:19:42 CEST 2005
To elaborate a bit on Harold's reply, the use of a "spaghetti plot"
for more than 4 or 5 groups is not recommended. Consider the
longitudinal data "sleepstudy" in the Matrix package. A spaghetti
plot can be produced by
> data(sleepstudy, package = "Matrix")
> library(lattice)
> xyplot(Reaction ~ Days, sleepstudy, groups = Subject, type = c('g','l'), aspect = 'xy')
Now compare this to the result of
> xyplot(Reaction ~ Days | Subject, sleepstudy, type = c('g','p','r'), aspect = 'xy')
which is a lattice plot with the data for each subject in a separate
panel. Even better is to use
> xyplot(Reaction ~ Days | Subject, sleepstudy, type = c('g','p','r'), aspect = 'xy',
+ index.cond = function(x, y) coef(lm(y ~ x))[1])
where the panels are ordered according to a characteristic of the data
(the intercept for the per-subject regression line) rather than in the
more-or-less random order created by the subject number.
library(lattice)
xyplot(Reaction ~ Days
On 9/16/05, Doran, Harold <HDoran at air.org> wrote:
> There is interaction.plot(), but, the trellis graphics in lattice are
> much better. You might want to check these out.
>
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Marc Bernard
> Sent: Friday, September 16, 2005 8:58 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] plot spaghetti data
>
> Dear All,
>
> I wonder if there is an R function to plot longitudinal data (spaghetti
> plots)...
> I've seen the function "is.longitudinal" but without any succes...
>
> Thanks a lot in advance,
>
> Bernard
>
>
> ---------------------------------
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list