[R] lattice: adding text to plots
Ritwik Sinha
ritwik.sinha at gmail.com
Mon Oct 9 06:26:19 CEST 2006
Hi Everyone,
I know there was a thread recently that dealt with a similar issue,
but this one is a little different.
I have the following data frame
DF <- data.frame(x = 1:12, y1 = rnorm(12), y2 = rnorm(12), g =
gl(2,6), h = rep(c("1", "2"), 6), f = c(rep(c("1-1","1-2"),3),
rep(c("2-1","2-2"),3)))
I essentially want this plot
xyplot(y1+y2~x|g*h, data=DF, type="l")
However, now I want to add a different text to each panel, the text
being from column "f" of the data frame. In other words, I want text
"1-1" in the panel where g=1 and h=1 and so on. I tried to pass groups
and subscript to the panel function but could not get what I was
looking for. The following attempt does not work.
xyplot(y1+y2~x|g*h, data=DF, type="l", auto.key=TRUE,
panel=function(x,y,..., groups, subscripts){panel.xyplot(x,y,...);
panel.text(x=4,y=0, labels=DF$f[subscripts])})
My R version is 2.2.1 and lattice version is 0.12-11 (sorry they are
not the latest ones, these are on the server).
--
Ritwik Sinha
Graduate Student
Epidemiology and Biostatistics
Case Western Reserve University
ritwik.sinha at gmail.com | +12163682366 | http://darwin.cwru.edu/~rsinha
More information about the R-help
mailing list