【问题标题】:How to plot CDF in R如何在 R 中绘制 CDF
【发布时间】:2012-07-09 15:30:28
【问题描述】:

我正在尝试使用以下代码使用ecdf() 函数绘制 CDF 图:

> x<-ecdf(data$V6)

> summary(x)
 Empirical CDF:   2402 unique values with summary
 Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
 3392     71870    120100    386100    219000 158600000 

plot(x, log='x')
    Error in plot.window(...) : Logarithmic axis must have positive limits

我的数据集呈指数增长,因此我希望在 x 轴上具有对数刻度。当我不使用log="x" 时,它可以工作,但情节并不好。我需要 x 轴是对数的。有什么想法吗?

【问题讨论】:

  • 顺便说一句,我尝试添加xlim=c(0,158600000),但出现另一个错误:nonfinite axis limits [GScale(-inf,8.2003,1, .); log=1]

标签: r distribution probability cdf


【解决方案1】:

这里有一些代码可以重现您的问题:

x <- seq(2e3, 1e9, length.out=2000)
ex <- ecdf(x)
plot(ex, log="x")
Error in plot.window(...) : Logarithmic axis must have positive limits

现在,将绘图限制设置为c(0, 1e9)

plot(ex, xlim=c(0, 1e9), log="x")
Warning message:
In plot.window(...) : nonfinite axis limits [GScale(-inf,9,1, .); log=1]
Warning messages:
1: nonfinite axis limits [GScale(-inf,9,1, .); log=1] 
2: nonfinite axis limits [GScale(-inf,9,1, .); log=1] 

解决方法:设置xlim为c(1, 1e9),即设置下限为正数:

plot(ex, xlim=c(1, 1e9), log="x")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-14
    • 1970-01-01
    • 1970-01-01
    • 2012-03-11
    • 2012-12-22
    • 1970-01-01
    • 2013-10-23
    • 2011-03-13
    相关资源
    最近更新 更多