累积直方图,Y轴为百分比

时间:2012-11-12 15:35:18

标签: r plot histogram percentage

我希望在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 个答案:

答案 0 :(得分:21)

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

plot(ecdf(x))

产生:

enter image description here

答案 1 :(得分:2)

还可以尝试:

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

答案 2 :(得分:2)

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

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

答案 3 :(得分:1)

对于整洁的方法,请尝试:

plot.ecdf(x)