[R] plotting order of lines in xyplot panels while using conditioning variable and groups

RICHARD PITMAN richard.pitman3 at btopenworld.com
Tue Jun 19 12:19:51 CEST 2007


I am using the following code:

library(lattice)
data<-read.csv("data.csv")
attach(data)

fig<-xyplot(S_t~month|event,
       key    = list(text=list(lab=c("Time to first CV
event - Data",
                                     "Survival post
first CV event - Model",
                                     "Survival post
first MIA/CA event - Data",
                                     "Survival post
first CVA event - Data",
                                     "Survival post
first TIA event - Data",
                                     "Survival post
first CVA/TIA event - Model"),
                               font=2,
                               cex=0.55),
                     lines=list(col=c("red",
                                      "magenta",
                                      "blue",
                                      "brown"),
                                type="l",
                                cex=0.55,
                                lwd=1.5,
                                pch=0:1),
                     corner=c(0,0),x=0.75,y=0.75),
       group  = group,
       index.cond = list(c(4,5,6,7,1,2,3)),
       type   = "l",
       lwd    = "3",
       ylim   = c(0,1.5),
       layout = c(4,2),
       col    = c("red","magenta","blue","brown"),
       pch    = 0:3,
       cex    = 0.5,
       ylab   = "cumulative probability",
       xlab   = "months",
     )
print(fig)

However, in each panel, the order in which the lines
are printed is suboptimal as some shorter lines are
obscured under longer lines. I am having some trouble
finding a method to change the order in which curves
are plotted in each panel. I have tried reordering the
levels in data$group:

data$group<-factor(data$group,
levels=c("CV_model_event_1","CV model event 2","CV
event
1","CV_event_2","CV_event_2_CVA","CV_event_2_TIA"))

but this changed nothing.

Any suggestions gratefully received.

TIA

Richard



More information about the R-help mailing list