[R] Lattice xyplot
Bert Gunter
bgunter.4567 at gmail.com
Mon May 1 16:34:09 CEST 2017
Yes. type = "l" connects the points in the order given in the data, so
if the x's are not already ordered, the plots will be different after
ordering the x's.
e.g.
> x <- c(3,1,2,4,6,5)
> y <- 11:16
> xyplot(y~x. type = "l")
As for why ... that's just the way it was designed. You can always
order the data first, if you don't want this default.
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Sun, Apr 30, 2017 at 6:07 PM, array chip via R-help
<r-help at r-project.org> wrote:
> 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
> ______________________________________________
> R-help at 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.
More information about the R-help
mailing list