How to create a cumulative graph in R

d-cubed picture d-cubed · Jul 21, 2016 · Viewed 8.4k times · Source

Is there a cumulative graph package in R? Or how might I create a cumulative graph in R? For example, given values of 2, 4, 2, 2, they values should be plotted as 2, 6, 8, 10 d3 example here. Then forming a stair step pattern as with other cumulative records

Answer

thelatemail picture thelatemail · Jul 21, 2016

As per ?plot.default - there is a "stairs" plotting method, which can be combined with cumsum() to give the result you want I think:

plot(cumsum(c(2,4,2,2)), type="s")

enter image description here