当我执行以下代码时(数据集是格子包的一部分):
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"))), ...)
}
) 我得到了下面的图表:

如何从左到右获得红色和绿色的交替颜色?(我注意到,如果我删除自定义面板,它可以正常工作,但我希望保留灰色参考线。)
谢谢。
发布于 2017-04-23 18:43:07
如果您愿意使用填充而不是边框来区分年份,我可以为您提供一个解决方案。我还在一个似乎是错误的地方改变了颜色的顺序(?),并删除了一些冗余的代码。
bwplot(yield ~ variety, data = barley, box.width = 1 / ngroups,
groups = year, scales = (x = list(rot = 45)),
par.settings = list(superpose.polygon = list(col = c("green", "red"),
pch =c (15, 15)),
superpose.symbol = list(fill = c("green", "red"))),
auto.key = list(points = FALSE, rectangles = TRUE, space = "right"),
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(...)
}
)

https://stackoverflow.com/questions/43550500
复制相似问题