【发布时间】:2012-12-07 07:22:57
【问题描述】:
我想给直方图和累积直方图添加密度曲线,像这样:
这是我能做到的:
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")
【问题讨论】:
-
density与frequency的规模不同。如果您进行更多搜索,我很确定您会在 SO 中找到有效的示例。您在发帖之前确实搜索过 SO,对吧? -
@DWin 谢谢你的建议,我都看过了,但我不知道如何叠加累积和常规密度曲线...
标签: r graph plot base kernel-density