Let's consider a boxplot with ggplot:
p <- ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot()
I want the boxes to be filled with a plain color that depends on the mean value of the mpg, for instance from blue to red. I have played with the various group and fill arguments but using "mean(mpg)" always returned the global mean.