Skip to content

question on xyplot

2 messages · Zhongming Yang, Adaikalavan Ramasamy

#
Dear All:
 
In the attached file, I have 3 group patients, and there are 5 in each group (the groups are decided by the prefix of the idno). I want draw a repeat measurement comparison figure. My goal is to list 5 patients from same group on one  horizontal line. But xyplot sounds pick them randomly (or I was confused?). Could you please help me modify the following code to accomplish this?
 
Thanks
 
Zhongming Yang
 

library(nlme)
library(lattice)
md <- read.table('../data/sample.txt', header=T)
md <- groupedData(md ~ month | idno, data=md)
trellis.device(theme=col.whitebg())
xyplot(md ~ month | idno, data=md, main="title", 
   xlab="x", ylab="y", layout=c(5, 3),
   panel=function(x, y){
   panel.xyplot(x, y)
   panel.lmline(x, y, lty=2)
        }
   )
 




		
---------------------------------

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: sample.txt
Url: https://stat.ethz.ch/pipermail/r-help/attachments/20050315/abec4779/sample.txt
1 day later
#
As promised here is my reply. I am assuming that your problem is
changing the order of the xyplots by idno.


The plotting order in lattice is determined by the levels of md$idno. By
default it was reading the levels from top to bottom of the dataset as
unique(md$idno) would do. 

 library(nlme); library(lattice)
 md <- read.table('sample.txt', header=T)
 md <- groupedData(md ~ month | idno, data=md)

 levels( md$id ) # old levels that were causing the problem 
[1] "TP_603" "TP_549" "TP_642" "NN_533" "NN_619" "NN_833" "SN_683"
 "NN_577" "SN_594" "SN_616" "TP_842" "NN_675" "SN_673" "SN_828" "TP_855"

You see now that the original plotting order was determined by the
above. We can create and set the following new.levels as follows


 ( new.levels <- sort( levels(md$idno) ) )        # create new levels
[1] "NN_533" "NN_577" "NN_619" "NN_675" "NN_833" "SN_594" "SN_616"
"SN_673" "SN_683" "SN_828" "TP_549" "TP_603" "TP_642" "TP_842" "TP_855"

md$idno <- factor( md$idno, levels=new.levels )  # set the new levels


Now you proceed as you have done before.

trellis.device(theme=col.whitebg())
xyplot(md ~ month | idno, data=md, main="title", 
   xlab="x", ylab="y", layout=c(5, 3),
   panel=function(x, y){
   panel.xyplot(x, y)
   panel.lmline(x, y, lty=2)
        }
   )

BTW, I tried to play around with the 'index.cond' and 'perm.cond'
arguments in xyplot with no success. 

Hope this helps.

Regards, Adai
On Tue, 2005-03-15 at 10:58 -0800, Zhongming Yang wrote: