문제

I am trying to plot reverse ecdf (what="1-F" equivalent of Ecdf function in Hmisc) using ggplot.

Here is the data:

dat = data.frame(ID = rep(c(1001:1015),each=3),
             Month = rep(c("April", "July", "October")),
             Value = runif(45,2.0,14.6))

I could plot the ecdf for each Month using ggplot2:

ggplot(dat, aes(Value, colour = Month)) + stat_ecdf()

However, I need to plot the reverse ecdf for each month. I tried several ways but couldn't work it out. Any help appreciated!

Best,

db

도움이 되었습니까?

해결책

Better if you can share the data, but try:

series <- rnorm(1000, 200, 50)
n<-ceiling(max(series))
qplot(1:n,1-(ecdf(series)(1:n)))+geom_step()

다른 팁

Two more ways to do this as I was recently working on this for vaccine clinical trials:

  1. Use Hmisc Ecdf. This is straight forward and plots it out though bit difficult to figure out details on changing different elements of the graph.

  2. Calculate cumulative distribution and then 1-cumulative is reverse cumulative. Plot the reverse using ggplot2 using geom_step if you like a step function in the graph. The function below would use ecdf from base r to give you cumulative distribution and then 1-cumulative:

    rcdf <- function (x) {
    cdf <- ecdf(x)
    y <- cdf(x)
    xrcdf <- 1-y
    }
    

in the above rcdf is a user-defined function defined using ecdf.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top