Frede Aakmann Tøgersen
2006-Jan-31 07:15 UTC
[R] lattice: combining panel.xyplot with panel.abline - is thispossible?
Well, one way to do it is xyplot(y~time|id, data=dat,type='l', panel=function(x,y,subscripts,...){ panel.xyplot(x,y,subscripts,...) panel.abline(v=dat[subscripts,"cm1"]) panel.abline(v=dat[subscripts,"cm2"]) } ) Since I don't know what the dataframe 'mergeData' is I have used 'dat'. Best regards Frede Aakmann T??gersen Scientist Danish Institute of Agricultural Sciences Research Centre Foulum Dept. of Genetics and Biotechnology Blichers All?? 20, P.O. BOX 50 DK-8830 Tjele Phone: +45 8999 1900 Direct: +45 8999 1878 E-mail: FredeA.Togersen at agrsci.dk Web: http://www.agrsci.org This email may contain information that is confidential. Any use or publication of this email without written permission from DIAS is not allowed. If you are not the intended recipient, please notify DIAS immediately and delete this email.> -----Oprindelig meddelelse----- > Fra: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] P?? vegne af S??ren H??jsgaard > Sendt: 31. januar 2006 01:44 > Til: r-help at stat.math.ethz.ch > Emne: [R] lattice: combining panel.xyplot with panel.abline - > is thispossible? > > Consider this data frame: > > dat<-data.frame(id=gl(3,5),time=rep(1:5,3),cm1=rep(c(2,3,4),ea > ch=5),cm2=rep(c(2.5,3.5,4.5),each=5),y=rnorm(15)) > > > dat > id time cm1 cm2 y > 1 1 1 2 2.5 -1.0824549 > 2 1 2 2 2.5 -0.7784834 > 3 1 3 2 2.5 -1.7783560 > 4 1 4 2 2.5 0.5056637 > 5 1 5 2 2.5 -0.1967505 > 6 2 1 3 3.5 1.1643136 > 7 2 2 3 3.5 -1.4323765 > 8 2 3 3 3.5 0.6810645 > 9 2 4 3 3.5 1.1310363 > 10 2 5 3 3.5 1.5677158 > 11 3 1 4 4.5 1.6394222 > 12 3 2 4 4.5 1.2024161 > 13 3 3 4 4.5 0.1784666 > 14 3 4 4 4.5 -1.3260668 > 15 3 5 4 4.5 -0.2711263 > > > I would like to plot y against time with a panel for each id, > i.e. with something like > > xyplot(y~time|id, data=dat,type='l') or > > xyplot(currCow.mean~currCow.cm|cowid, data=mergeData, type='l', > panel=function(x,y,...){ > panel.xyplot(x,y) > } > ) > > > Then, I would additionally like to have two vertical lines in > each panel, and these are defined by cm1 and cm2. My > understanding of xyplot is that id will give a partitioning > of data into subsets, so I expected to be able to get each > subset into the panelfunction and from there I can extract > cm1 and cm2 and call panel.abline(a,b)... > > 1) Is that possible? > 2) Are there other ways of achieving what I want? > > Appologies if this is trivial... > > Best regards > > S??ren > > ______________________________________________ > 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 > >