Skip to content
Prev 327470 / 398502 Next

histogram with bars colored according to a vector of values

On 07/26/2013 12:13 PM, john d wrote:
Hi John,
Try this:

dat$xcut<-cut(dat$x,breaks=-5:5)
library(plotrix)
barcol<-color.scale(by(dat$y,dat$xcut,mean),extremes=c("red","blue"))
hist(dat$x,breaks=-5:5,col=barcol)

Jim