r - Make histograms of stacked rectangles rather than columns -
with following code, histogram below
x <- rnorm(100) hist(x,col="gray") what can display bars stacked rectangles (visible outlines, rather change in fill color) instead of uniform columns? each rectangle represents frequency of, example, 1, although want able change through parameter.

here function started (it modicication of part of examples tkbrush function in teachingdemos package):
rechist <- function(x,...){ tmp <- hist(x,plot=f) br <- tmp$breaks w <- as.numeric(cut(x,br,include.lowest=true)) sy <- unlist(lapply(tmp$counts,function(x)seq(length=x))) <- max(sy) sy <- sy/my <- 1/my sy <- sy[order(order(x))] plot.new() plot.window(xlim=range(br), ylim=c(0,1)) rect(br[w], sy-my, br[w+1], sy, border=true, col='grey') rect(br[-length(br)], 0, br[-1], tmp$counts*my) axis(1) } rechist( iris$petal.length )
Comments
Post a Comment