Afshartous, David
2007-Jul-03 16:35 UTC
[R] xyplot and autokey, maintaining colors specified via "col" in key
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.
Gabor Grothendieck
2007-Jul-03 17:00 UTC
[R] xyplot and autokey, maintaining colors specified via "col" in key
Don't know what you did regarding par.settings to not get the desired result but that is, in fact, the way to go since both the key and the plot lines will get their colors from that: 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 ), par.settings = list(superpose.line = list(col = rainbow(3)))) On 7/3/07, Afshartous, David <afshart at exchange.sba.miami.edu> wrote:> > 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. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >