Skip to content
Back to formatted view

Raw Message

Message-ID: <4B5C6E6F.50204@ucalgary.ca>
Date: 2010-01-24T15:59:43Z
From: Peter Ehlers
Subject: lattice ltext
In-Reply-To: <4B5B8F75.8040301@gvdnet.dk>

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