9

I am using xyplot from the lattice package, and I want to change the color of hte header. Currently, it is an ugly light-orange color.

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)
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Spurious
  • 1,903
  • 5
  • 27
  • 53
  • 2
    I really like **lattice** but also dislike some of its default settings. Fortunately, it makes it easy to supply your own themes (i.e. lists of settings that can be passed in to `par.settings=`). For a few examples of what's possible, install the **latticeExtra** package and then run `library(latticeExtra); example("custom.theme")`. For spatial data, the **rasterVis** package provides several additional themes. – Josh O'Brien Apr 09 '13 at 17:38

1 Answers1

17

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.

Community
  • 1
  • 1
Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455