I have created a multi-panel plot using the lattice package in R with the below code. The plot has four panels each of which contains a histogram. I would like the bars in each panel to be a unique colour, but I am having trouble achieving this.
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")))
I tried adding as.table=TRUE, groups=year, col=c("red", "blue", "green", "purple")
to the code as was suggested in a related question found here R: specifying color for different facets / panels in lattice, but all this did was to alternate the colours of the bars WITHIN each panel rather than BETWEEN panels.
Any suggestions on how to remedy this would be much appreciated!
If possible, I would also like to know how a similar effect can be achieved on the strip above each panel (i.e. whether the background of each panel strip can be set individually rather than just for all panels in the entire plot?)
Many thanks!