Hi all, how can I change the background color in lattice strips according to a factor level, eg: library(lattice) x <- rnorm(100) y <- sqrt(x) f <- gl(2, 50, c("A", "B")) xyplot(y ~ x | f) I like to change the background color of the strips according to the levels in f and tried several things like this with no success: xyplot(y ~ x | f, strip=strip.custom(bg=c("red", "green"))) Is this possible? Thanks, Sven
One way is to use the argument par.settings get the right name names(trellis.par.get()) or str(trellis.par.get()) to find the list names to change then xyplot(y ~ x | f, par.settings = list(strip.background = list(col = c(your colours)) ) Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England ARMIDALE NSW 2351 Email: dmackay9 at pobox.une.edu.au home: mackay at northnet.com.au Phone: 02 6772 9794 At 20:01 04/12/06, you wrote:>Hi all, >how can I change the background color in lattice strips according to a >factor level, eg: > >library(lattice) >x <- rnorm(100) >y <- sqrt(x) >f <- gl(2, 50, c("A", "B")) >xyplot(y ~ x | f) > >I like to change the background color of the strips according to the >levels in f and tried several things like this with no success: > >xyplot(y ~ x | f, strip=strip.custom(bg=c("red", "green"))) > >Is this possible? > >Thanks, Sven > >______________________________________________ >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.
On 12/4/06, Sven Garbade <Sven.Garbade at med.uni-heidelberg.de> wrote:> Hi all, > how can I change the background color in lattice strips according to a > factor level, eg: > > library(lattice) > x <- rnorm(100) > y <- sqrt(x) > f <- gl(2, 50, c("A", "B")) > xyplot(y ~ x | f) > > I like to change the background color of the strips according to the > levels in f and tried several things like this with no success: > > xyplot(y ~ x | f, strip=strip.custom(bg=c("red", "green"))) > > Is this possible?Yes, you just have to write a custom strip function (slightly beyond what strip.custom is capable of): xyplot(y ~ x | f, strip = function(..., which.panel, bg) { bg.col = trellis.par.get("strip.background")$col; ## or bg.col = c("red", "green") if you prefer strip.default(..., which.panel = which.panel, bg = rep(bg.col, length = which.panel)[which.panel]) }) This will only work when you have one conditioning variable (otherwise 'which.panel' won't be a scalar), but you haven't told us what you want to happen otherwise. -Deepayan