R-如何绘制累积线

时间:2020-07-28 08:25:39

标签: r plot statistics histogram cumulative-sum

我的问题如下:

我必须绘制一条曲线,该曲线以使用寿命(x)来显示故障数(y),但要以累积的方式显示-这就是我要努力的地方!

第二张图片给出了解决方案,第一张图片给出了我的代码(我认为只有图的类型应该不同)

my code solution

非常感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我无法复制您的数据,所以这更多是评论,然后是一个完整的解决方案。

n <- sum(h$counts)          # This should sum up to the number of observations
y <- cumsum(h$counts) / n   # Your y values
x <- h$mids                   # I assume these to be your x-axis value, but this might need an edit.
plot(x = x, y = y, type = "l")

最后,您可以通过abline()函数在各个点处添加垂直线和水平线。