【发布时间】:2014-06-28 22:57:36
【问题描述】:
我使用 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")))
我尝试按照此处R: specifying color for different facets / panels in lattice 的相关问题中的建议将as.table=TRUE, groups=year, col=c("red", "blue", "green", "purple") 添加到代码中,但所做的只是在每个面板内而不是在面板之间交替条形的颜色。
任何有关如何解决此问题的建议将不胜感激!
如果可能的话,我也想知道如何在每个面板上方的条上实现类似的效果(即是否可以单独设置每个面板条的背景,而不仅仅是为整个情节中的所有面板设置?)
非常感谢!
【问题讨论】:
标签: r plot panel histogram lattice