I want to add density curve to histogram and cumulative histogram, like this:
Here is as far I can go:
hist.cum <- function(x, plot=TRUE, ...){
h <- hist(x, plot=FALSE, ...)
h$counts <- cumsum(h$counts)
h$density <- cumsum(h$density)
h$itensities <- cumsum(h$itensities)
if(plot)
plot(h)
h
}
x <- rnorm(100, 15, 5)
hist.cum(x)
hist(x, add=TRUE, col="lightseagreen")
#
lines (density(x), add = TRUE, col="red")
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…