Here is the lattice
version. Essentially you define a vector of colors, which I did outside the histogram()
function. In the histogram()
function you use a panel.function
which will allow you to make each panel look different. You call panel.histogram
and tell it to pick a color based on packet.number()
. That function just returns an integer indicating which panel is being drawn, panel 1 gets red, panel 2 gets blue etc.
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))
colors<-c("red","blue","green","purple") #Define colors for the histograms
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=colors, #passing your colors to col
panel=function(x, col=col,...){
panel.histogram(x,col=col[packet.number()],...) #gets color for each panel
}
))