当我执行以下代码时(数据集是 lattice 包的一部分):
ngroups <- length(unique(barley$site)) + 1
bwplot(yield ~ variety, data = barley, box.width = 1/ ngroups,
groups = year, scales=(x=list(rot=45)),
auto.key = list(points = FALSE, rectangles = TRUE, space = "right"),
par.settings=list(box.rectangle = list(col=c("red", "green"), lwd=3),
superpose.polygon=list(col=c("green", "red"), pch=c(15,15))
),
panel.groups = function(x, y, ..., group.number) {
panel.bwplot(x + (group.number-1.5)/ngroups, y, ...)
},
panel=function(...) {
panel.grid(h = -1, v=0)
panel.superpose(par.settings=list(box.rectangle=list(col=c("green", "red"))), ...)
}
)
我得到以下图表:
如何从左到右为盒子获得红色和绿色的交替颜色?(我注意到如果我删除自定义面板效果很好,但我想保留灰色参考线。)
谢谢。