[R] another xyplot question
Deepayan Sarkar
deepayan.sarkar at gmail.com
Fri Jul 3 02:27:13 CEST 2009
On Wed, Jul 1, 2009 at 10:38 PM, jlfmssm<jlfmssm at gmail.com> wrote:
> I have a data set like this
>
> ID=c("A","A","A","A","A","A","A","B","B","B","B","B","B","B")
> s=c(1.1,2.2,1.3,1.1,3.1,4.1,4.2,1.1,2.2,1.3,1.1,3.1,4.1,4.2)
> d=c(1,2,3,4,5,6,7,1,2,3,4,5,6,7)
> t=c(-3,-1,0,1,2,3,4,-3,-2,-1,0,1,2,3)
>
> mydata<-data.frame(cbind(as.character(ID),as.numeric(s),as.integer(d),as.numeric(t)))
> colnames(mydata)=c("ID","S","d","t")
> attach(mydata)
>
> library(lattice)
>
> Key <- list(text = list(c("FDL", "FDP")), points = list(pch = c("*","o"),col
> = c("red", "blue"), cex = 2), space = "right")
>
> xyplot(S ~ d | ID,groups = t < 0,col = c("red", "blue"),pch = c("*",
> "o"),scales = list(x = list(at=c(min(d),d[which
>
> (t==0)],max(d)),alternating =c(1,2))),key = Key,cex = 2,type = "b")
>
> Actually, I want to have :
>
> location of tick marks along the axis is:
>
> For A
> 1,3,7
>
> because for A
> min(d)=1
> d[which(t==0)]=3
> max(d)=7
>
> For B
> 1,4,7
> min(d)=1
> d[which(t==0)]=4
> max(d)=7
>
> But the location of tick marks along the axis from my code doesn't depend on
> A or B.
> Does anyone know how to change this?
Lattice doesn't support data-dependent axis annotation (it's possible
using panel.axis if you really want, but there are several other
things you will need to tweak).
If you want to mark certain points, use something like
xyplot(S ~ d | ID, groups = t < 0,
par.settings = simpleTheme(col = c("red", "blue"),
pch = c("*", "o"),
cex = 2),
auto.key = list(text = c("FDL", "FDP")), type = "b",
panel = function(x, y, ..., subscripts) {
tt <- t[subscripts]
at <- c(min(x), x[tt ==0], max(x))
panel.abline(v = at, col = "darkgrey")
panel.xyplot(x, y, ..., subscripts = subscripts)
})
-Deepayan
More information about the R-help
mailing list