plot - Using gradient displays for histograms in r -
i have dataset (n = 9,141,954) looks this
data<-c(rep(1, times=401),rep(2,times=443789),rep(3,times=5276376),rep (4,times=3003895),rep(5,times=404108),rep(6,times=13181),rep(7,times=205))
which histogram looks this:
hist(data,prob=t,breaks=5)
from left right, want display colours "darkgreen" "chartreuse4" "yellowgreen" "yellow" "orange2" "red" , "red3"
which know can using col=c("darkgreen","chartreuse4", ....etc), display these colours gradient across histogram, weighted relative contribution of each of values dataset. example, value = 1 makes 0.004% of cell values (401/9141954*100), , value = 4 makes 32.9% of data. therefore, gradient display have 0.004% assoicated "darkgreen" 32.9% associated "yellow", , on rest of values/colours.
does know how can done???
something this?
res <- hist(data,breaks=5) plot(res) cols <-c("darkgreen","chartreuse4","yellowgreen","yellow","orange2","red","red3") colcombos <- data.frame(embed(cols,2)[,2:1],nums=round(res$density*600)) selcols <- unlist( apply(colcombos,1,function(x) colorramppalette(c(x[1],x[2]))(x[3])) ) dens <- 100 bar.dens <- 1/100 rect( seq(1,7-bar.dens,bar.dens), 0, seq(1+bar.dens,7,bar.dens), rep(res$counts,each=dens), col=selcols, border=na ) plot(res,add=true)
result, doesn't exciting unfortunately, colours there, if plot barplots of uniform height:
Comments
Post a Comment