Cumulative histogram with percentage on the Y axis

Gianni Spear picture Gianni Spear · Nov 12, 2012 · Viewed 17.2k times · Source

I wish to plot in R project a cumulative histogram where on the Y axes is reported the percentage instead of the frequency

x <- c(rnorm(100), rnorm(50, mean=2,sd=.5))
h <- hist(x, plot=FALSE, breaks=20)
h$counts     <- cumsum(h$counts)
h$density    <- cumsum(h$density)
plot(h, freq=TRUE, main="(Cumulative) histogram of x", col="white", border="black")
box()

Thanks for help

Answer

Gavin Simpson picture Gavin Simpson · Nov 12, 2012

Isn't this a plot of the empirical cumulative distribution function? As in

plot(ecdf(x))

which produces:

enter image description here