[R] lattice: combining panel.xyplot with panel.abline - is this possible?

Søren Højsgaard Soren.Hojsgaard at agrsci.dk
Tue Jan 31 01:44:23 CET 2006


Consider this data frame:
 
dat<-data.frame(id=gl(3,5),time=rep(1:5,3),cm1=rep(c(2,3,4),each=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




More information about the R-help mailing list