[R] xyplot and autokey, maintaining colors specified via "col" in key

Afshartous, David afshart at exchange.sba.miami.edu
Tue Jul 3 18:35:08 CEST 2007


 
All,

When specifying colors to xyplot w/ a groups argument, using
auto.key no longer maintains the colors properly.  I've searched
the docs and help but haven't found exactly what I need ... I saw
a few examples in the archives involving par.settings but that doesn't
seem to do it. I also saw some people using key instead of auto.key, but
that didn't seem consistent.  Is there a quick fix to the example code
below?

cheers,
Dave

dat.ex = data.frame(  rep(c(1:6), each=6), c(rnorm(12), rnorm(12, 1),
rnorm(12, 2)), rep(c(1:6), 6),
rep(c("Drug1", "Drug2", "Placebo"), each=12) )
names(dat.ex) = c("patient.no", "outcome", "time", "drug")


## colors in xyplot agree w/ colors in key, colors not specified:
xyplot(outcome ~ time, dat.ex, groups=drug, type=c("g", "smooth"), 
auto.key = list(space = "top",  text = levels(dat.ex$drug),
points=FALSE, lines=TRUE ) )

## colors in xyplot do NOT agree w/ colors in key when colors changed:
xyplot(outcome ~ time, dat.ex, groups=drug, type=c("g", "smooth"), 
auto.key = list(space = "top",  text = levels(dat.ex$drug),
points=FALSE, lines=TRUE ),
col = c(1,2,3)  )

i.e., the key is still generated w/ the "old" colors.



More information about the R-help mailing list