[R] lattice ltext

Peter Ehlers ehlers at ucalgary.ca
Sun Jan 24 16:59:43 CET 2010


Troels Ring wrote:
> Dear friends - please give me a hand.
> I have a dataset of 40 patients in two groups observed on three 
> occasions. I only want to plot a line
> for each patient in the two groups. I use the ltext  function to put the 
> patient  number but fail to make lattice understand the numbers as 
> unique since apparently it starts all over with 1:20 for each panel 
> instead of respecting my desires to have 1:20 and then 21:40.
> I'm on windows vista, R2.9.2
> Best wishes
> Troels
> 
> score <-  runif(120,0,100)
> pt <- gl(40,3,120)
> times <- rep(c(0,3,6),40)
> trt <- gl(2,60,120)
> ach <- data.frame(score=score,pt=pt,times=times,trt=trt)
> 
> myPanel <- function(x,y,...){
> panel.xyplot(x,y,...)
> ltext(x-.1,y+1,paste(pt),cex=0.5) }
> 
> xyplot(score~times|trt,groups=pt,type=c("p","l"),ach,
> panel=myPanel)
> 
You'll need subscripts:

myPanel <- function(x,y,subscripts,groups,...){
   panel.superpose(x,y,subscripts,groups,...)
   ltext(x-.1,y+1,as.character(groups)[subscripts],cex=0.5)}

xyplot(score~times|trt, groups=pt, type=c("p","l"),
   data=ach, panel=myPanel)

  -Peter Ehlers

-- 
Peter Ehlers
University of Calgary



More information about the R-help mailing list