简体   繁体   English

R-如何累计plot行

[英]R- how to plot cumulative lines

my problem is the following:我的问题如下:

I have to plot a curve which shows the number of breakdowns (y) by the service life (x) but in a cumulative way - and that's the point where I struggle!!我必须 plot 一条曲线,它显示按使用寿命 (x) 划分的故障次数 (y),但以累积的方式 - 这就是我挣扎的地方!

The solution is given in the second Picture, my code in the first (I think only the type of the plot should be different)解决方案在第二张图片中,我的代码在第一张中(我认为只有 plot 的类型应该不同)

my code solution我的代码解决方案

Thanks so much for every help!!非常感谢您的帮助!!

I can't replicate your data, so this is more of a comment, then a complete solution.我无法复制你的数据,所以这更像是一个评论,然后是一个完整的解决方案。

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")

Finally, you can add the vertical and horizontal lines via the abline() function at the respective points.最后,您可以通过abline() function 在相应的点添加垂直线和水平线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM