Dear all, I am new to lattice, so would appreciate anyone's help on the 
questions below. I am using xyplot to plot some trend in my dataset. Using the 
example dataset attached, I am trying to plot variable "y" over variable "time" 
for each subject "id":
dat<-read.table("dat.txt",sep='\t',header=T,row.names=NULL)
xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", "l"),  
xlab = "Time", ylab = "Y")

It appears that it just worked fine. But if I sort the "dat" first, the plot 
will look somewhat different!
dat<-dat[order(dat$id, dat$time),]xyplot(y ~ time, data=dat, groups=id, aspect 
= "fill", type = c("p", "l"),  xlab = "Time", ylab = "Y")
Why is that? Do you need to sort the data first before using xyplot? Why xyplot 
can not understand the dataset unless it is sorted first?
Thanks,
John
id      time    y
107     0       6.5
107     1       5.1
107     2       4.2
112     0       5.6
107     3       6.9
112     1       4
112     2       1
119     0       7.6
112     3       4.9
119     1       5.7
120     0       7.1
203     0       7.4
120     2       2.1
203     1       6.3
123     0       6.8
203     2       3.8
119     3       6.1
123     1       3.9
123     2       3
120     3       6
203     3       7.6
207     0       5.8
207     1       3.1
123     3       5.7
209     3       3.6
208     0       4.4
130     0       5.5
131     0       6.9
133     0       5.7
134     0       5.1
209     0       4.9
128     2       2.9
128     1       4.5
130     2       5.9
131     1       6.9
133     2       2.6
133     1       5.7
403     2       3.1
403     0       4.5
128     0       4.5
134     2       2.3
207     3       4.8
130     3       4.9
207     2       2.3
130     1       3.8
131     2       3.9
133     3       3.1
134     1       2.8
209     1       4.2
208     3       2.3
208     1       5.3
208     2       0.8
128     3       4.4
131     3       6.2
209     2       5.7
134     3       4.1
403     3       2.5
119     2       2.3
120     1       3.8
403     1       3.2
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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