How to plot CDF in R

Nasir picture Nasir · Jul 9, 2012 · Viewed 7.5k times · Source

I am trying to plot a CDF plot using ecdf() function using the following code:

> 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

My dataset grows exponentially so I want to have log scale on x axis. When I don't use log="x" it works but the plot is not good. I need the x axis to be logarithmic. Any ideas?

Answer

Andrie picture Andrie · Jul 9, 2012

Here is some code that reproduces your problem:

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

Now, set the plot limits to 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] 

The solution: set the xlim to c(1, 1e9), i.e. set the lower limit to a positive number:

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

enter image description here