How can I change the color of the header in a xypl

2019-02-07 00:15发布

问题:

have a question concerning a xyplot: how can i change the color of the header?!?! In case, this ugly light-orange color! Thank you in advance.

library(lattice)

x <- c(1:10, 1:10)
y <- c(10:1, 10:1)
z <- c(1:10, seq(1,20, by=2))
a = c(rep("one",10),rep("two",10))
DF <- data.frame(x, y, z, a)
xyplot(y ~ x | a, groups = z < 5, data = DF, col = c("black", "red"),
 pch=20, cex=0.3)

回答1:

You need to reset the contents of trellis.par.get()$strip.background$col.

To do this for a single plot, use the par.settings= argument:

xyplot(y ~ x | a, groups = z < 5, data = DF, col = c("black", "red"),
       pch = 20, cex = 0.3, 
       par.settings = list(strip.background=list(col="lightgrey")))

To more persistently reset the strip background color, use trellis.par.set():

trellis.par.set(strip.background=list(col="lightgrey"))

To see how you might have found this out yourself, try the following:

names(trellis.par.get())
trellis.par.get("strip.background")

Finally, for an example of more complicated (and aesthetically appalling) strip-background manipulations, see here.



标签: r plot lattice