I'm using ggplot2's stat_ecdf
to plot the cumulative distribution of times to event. However, some events are right-censored (not yet occurred). So, I want the cumulative distribution to not reach 1. As described in the documentation, na.rm
option is basically useless. Do I have to code my own ecdf...?
MWE
The problem is that stat_ecdf
includes no option to treat NA
as censored, so the distribution always reaches 1, including if the x-limits are adjusted (which seems fully incorrect).
library('ggplot2')
set.seed(0)
x = rbinom(8,20,.5) # true all data
# x[x>10] = NA # "censoring" as NA - same problem
g = ggplot(data.frame(x=x),aes(x=x)) +
stat_ecdf(na.rm=TRUE) + # na.rm does nothing
lims(x=c(0,10)) # "censoring" as xlim - cdf is re-scaled to the visible data!?
# lims(x=c(0,20)) # no "censoring" - correct
print(g)