【问题标题】:Cumulative histogram with percentage on the Y axisY 轴上带有百分比的累积直方图
【发布时间】:2012-11-12 15:35:18
【问题描述】:

我希望在 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()

感谢您的帮助

【问题讨论】:

  • hist(data, freq=FALSE) 中设置freq=FALSE 以获得概率“百分比”而不是频率
  • 是否可以用线条添加/更改条形?

标签: r plot histogram percentage


【解决方案1】:

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

plot(ecdf(x))

产生:

【讨论】:

    【解决方案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】:

      也试试:

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

      【讨论】:

        【解决方案4】:

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

        plot.ecdf(x)
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-12-29
          • 2019-11-01
          • 1970-01-01
          • 2019-03-12
          • 2018-09-08
          相关资源
          最近更新 更多