如何在R中绘制CDF

Nas*_*sir 3 r distribution probability cdf

我正在尝试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
Run Code Online (Sandbox Code Playgroud)

我的数据集以指数方式增长,因此我希望在x轴上具有对数比例.当我不使用log="x"它工作,但情节不好.我需要x轴是对数的.有任何想法吗?

And*_*rie 10

以下是一些可以重现您的问题的代码:

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

现在,将绘图限制设置为 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] 
Run Code Online (Sandbox Code Playgroud)

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

plot(ex, xlim=c(1, 1e9), log="x")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述