I have a data of machine failures with one column which defines time between failures (tbf)
structure(list(tbf = c(2441, 2934, 4285, 2285, 4027, 2419, 2437, 2519, 3294, 2858, 3023, 2567, 3112, 2283, 3068, 2215, 3915, 2354.290323, 2477, 2258, 2742.5, 5198, 2837, 3282, 2474, 2883, 3837, 5054, 4874, 3559.5, 2783, 4246, 2602)), .Names = "tbf", class = "data.frame", row.names = c(NA, -33L))
I want to plot a cumulative occurrence graph. I can do that using
library(ggplot2)
ggplot(mydf, aes(x = tbf)) + stat_ecdf()
which creates a plot as shown below
However, I want a straight line fit into this plot. I do not want uneven line but a straight line fitted to it. I tried
library(dplyr)
# add cumulative time and failures
mydf <- mydf %>% mutate(cumm_time = cumsum(tbf), cumm_fmode = row_number())
# fit linear regression
fit <- lm(cumm_time ~ cumm_fmode, data = mydf)
# plot points
plot(mydf$cumm_time, mydf$cumm_time)
# plot straight line
abline(fit)
However, I get the figure the one below::
My requirement is to get a figure something like::
Where am I getting it wrong? Any help will be appreciated.