-1

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 belowenter image description here

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:: enter image description here

My requirement is to get a figure something like::

enter image description here

Where am I getting it wrong? Any help will be appreciated.

4

1 回答 1

1

看起来您想在两个轴上制作一个具有相同变量的图?从这一行:plot(mydf$cumm_time, mydf$cumm_time),有一个错字,或者您正在绘制一个带有(cumsum(tbf))X 和 Y 轴上数据的因变量的图。

我会假设你打算输入plot(mydf$cumm_fmode, mydf$cumm_time).

如果你这样做,那么你的其余代码就可以了。

plot(mydf$cumm_fmode, mydf$cumm_time)
abline(fit)

将 x 更改为 mydf$cumm_fmode

于 2016-12-12T01:37:15.217 回答