我希望在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()
感谢您的帮助
答案 0 :(得分:21)
这不是经验累积分布函数的图吗?如在
plot(ecdf(x))
产生:
答案 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)