[R] Lattice xyplot
Duncan Mackay
dulcalma at bigpond.com
Mon May 1 17:04:23 CEST 2017
In addition to Berts comments
Once you change the order you change the non factored id' ordering. If you make it a factor it may be easier to see what is going on
I think I have copied correctly - see the differences
# original data
xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", "l"), xlab = "Time", ylab = "Y")
# order
dat2<-dat[order(dat$id, dat$time),]
xyplot(y ~ time, data=dat2, groups=id, aspect = "fill", type = c("p", "l"), xlab = "Time", ylab = "Y")
# make ID a factor
dat3 <- dat1
xyplot(y ~ time, data=dat3, groups=id, aspect = "fill", type = c("p", "l"), xlab = "Time", ylab = "Y")
# ordered + ID a factor
dat4 <- dat3
dat4<-dat[order(dat4$id, dat4$time),]
xyplot(y ~ time, data=dat4, groups=id, aspect = "fill", type = c("p", "l"), xlab = "Time", ylab = "Y")
Regards
Duncan
Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au
-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of array chip via R-help
Sent: Monday, 1 May 2017 11:07
To: r-help at r-project.org
Subject: [R] Lattice xyplot
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
More information about the R-help
mailing list