How could I get a cumulative histogram like this
x <- runif(100,0,10)
h <- hist(x)
h[["counts"]] <- cumsum(h[["counts"]])
plot(h)
with ggplot2?
I want also to draw a polygon like this
lines(h[["breaks"]],c(0,h[["counts"]]))
ggplot2r
How could I get a cumulative histogram like this
x <- runif(100,0,10)
h <- hist(x)
h[["counts"]] <- cumsum(h[["counts"]])
plot(h)
with ggplot2?
I want also to draw a polygon like this
lines(h[["breaks"]],c(0,h[["counts"]]))
Best Answer
To make cumulative histogram use
geom_histogram()
and then usecumsum(..count..)
fory
values. Cumulative line can be added withstat_bin()
andgeom="line"
andy
values calculated ascumsum(..count..)
.