我使用R中的lattice包创建了一个多面板图。该图有四个面板,每个面板都包含一个直方图。我希望每个面板中的条形图颜色是不同的,但我无法实现这一点。
Para = as.vector(rnorm(100, mean=180, sd=35))
Year = as.vector(c(rep(1,25),rep(2,25),rep(3,25), rep(4,25)))
df = as.data.frame(cbind(Para, Year))
library(lattice)
print(histogram(~ Para | Year, data = df, scales = list(cex = c(1.0, 1.0)),
layout = c(4, 1), type = "count",
xlab = list("Parameter", fontsize = 16),
ylab = list("Frequency", fontsize = 16),
strip = function(bg = 'white',...) strip.default(bg = 'white', ...),
breaks = seq(0, 300, by = 50), ylim = seq(0, 35, by = 10),
as.table = TRUE, groups = year, col = c("red", "blue", "green", "purple")))
我尝试添加
as.table=TRUE, groups=year, col=c("red", "blue", "green", "purple")
到代码中,正如在这里找到的相关问题所建议的那样R: specifying color for different facets / panels in lattice,但这只是交替每个面板内条形图的颜色而不是在面板之间。有什么建议可以解决这个问题将不胜感激!
如果可能的话,我还想知道如何在每个平面上方的条带上实现类似的效果(即是否可以单独设置每个平面条带的背景,而不仅仅是整个图中所有平面的背景?)
非常感谢!