这是一个干净且易于定制的解决方案。
myStripStyle()
,传递给的函数strip=
的论证xyplot()
使用计数器变量which.panel
选择颜色以及值factor.levels
对于当前正在绘制的面板。
如果您想尝试这些设置,只需添加一个browser()
定义内的某处myStripStyle()
并努力吧!
bgColors <- c("black", "green4", "blue", "red", "purple", "yellow")
txtColors <- c("white", "yellow", "white", "white", "green", "red")
# Create a function to be passed to "strip=" argument of xyplot
myStripStyle <- function(which.panel, factor.levels, ...) {
panel.rect(0, 0, 1, 1,
col = bgColors[which.panel],
border = 1)
panel.text(x = 0.5, y = 0.5,
font=2,
lab = factor.levels[which.panel],
col = txtColors[which.panel])
}
xyplot(yield ~ year | site, data = barley, strip=myStripStyle)