5

我希望在 R 项目中绘制一个累积直方图,其中在 Y 轴上报告百分比而不是频率

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()

感谢帮助

4

4 回答 4

21

这不是经验累积分布函数的图吗?如在

plot(ecdf(x))

产生:

在此处输入图像描述

于 2012-11-12T15:53:04.027 回答
3

对于柱状图直方图,您需要执行以下操作:

x <- c(rnorm(100), rnorm(50, mean=2,sd=.5))
hist( x,plot=FALSE) -> h # do a histogram of y and assign its info to h
h$counts <- cumsum(h$counts)/sum(h$counts) # replace the cell freq.s by cumulative freq.s
plot( h ) # plot a cumulative histogram of y

资料来源:http: //influentialpoints.com/Training/basic_statistics_cumulative_plot.htm

于 2017-09-13T22:59:42.167 回答
2

也试试:

plot( sort(x), (1:length(x))/length(x), type="l" )

于 2014-09-23T13:12:20.410 回答
1

对于一个简洁的方法尝试:

plot.ecdf(x)
于 2018-08-22T20:57:48.360 回答