2016-12-11 137 views
-1

我的机器故障数据与一列,其限定故障(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)) 

我要绘制的累积发生曲线图。我能做到这一点使用

library(ggplot2) 
ggplot(mydf, aes(x = tbf)) + stat_ecdf() 

它创建了一个情节如下图所示enter image description here

不过,我想直线拟合到这个情节。我不想要不平坦的线条,但是有一条直线适合它。我试图

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) 

不过,我得到下图的一个:: enter image description here

我的要求是得到一个人物像::

enter image description here

我在哪里得到它错了吗?任何帮助将不胜感激。

回答

1

它看起来像你想在两个轴上使用相同的变量绘制一个绘图?从这一行开始:plot(mydf$cumm_time, mydf$cumm_time),可能是拼写错误,也可能是在X轴和Y轴上绘制了数据因变量(cumsum(tbf))的绘图。

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

如果你这样做,那么你的代码的其余部分是好的。

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

changed x to mydf$cumm_fmode