Plotting CCDF of walking durations

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-03 05:28:20

问题


I have plotted the CCDF as mentioned in question part of the maximum plot points in R? post to get a plot(image1) with this code:

ccdf<-function(duration,density=FALSE)
{
freqs = table(duration)
  X = rev(as.numeric(names(freqs)))
  Y =cumsum(rev(as.list(freqs)));
  data.frame(x=X,count=Y)
}
qplot(x,count,data=ccdf(duration),log='xy')

Now, on the basis of answer by teucer on Howto Plot “Reverse” Cumulative Frequency Graph With ECDF I tried to plot a CCDF using the commands below:

f <- ecdf(duration)
plot(1-f(duration),duration)

I got a plot like image2.
Also I read in from the comments in one of the answers in Plotting CDF of a dataset in R? as CCDF is nothing but 1-ECDF.
I am totally confused about how to get the CCDF of my data.

Image1


Image2


回答1:


Generate some data and find the ecdf function.

x <- rlnorm(1e5, 5)
ecdf_x <- ecdf(x)

Generate vector at regular intervals over range of x. (EDIT: you want them evenly spaced on a log scale in this case; if you have negative values, then use sample over a linear scale.)

xx <- seq(min(x), max(x), length.out = 1e4)
#or
log_x <- log(x)
xx <- exp(seq(min(log_x), max(log_x), length.out = 1e3))

Create data with x and y coordinates for plot.

dfr <- data.frame(
  x = xx,
  ecdf = ecdf_x(xx),
  ccdf = 1 - ecdf_x(xx)
)

Draw plot.

p_ccdf <- ggplot(dfr, aes(x, ccdf)) + 
  geom_line() +
  scale_x_log10()
p_ccdf

(Also take a look at aes(x, ecdf).)




回答2:


I used ggplot to get desired ccdf plot of my data as shown below:

>>ecdf_x <- ecdf(x) 
>>dfr <- data.frame( ecdf = ecdf_x(x), 
>>ccdf = 1 - ecdf_x(x) ) 
>>p_ccdf <- ggplot(dfr, aes(x, ccdf)) + geom_line() + scale_x_log10() 
>>p_ccdf

Sorry for posting it so late. Thank you all!



来源:https://stackoverflow.com/questions/6680635/plotting-ccdf-of-walking-durations

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!