# How to create a cumulative sum plot in base R?

R ProgrammingServer Side ProgrammingProgramming

#### Artificial Intelligence : The Future Of Programming

15 Lectures 54 mins

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### C Programming from scratch- Master C Programming

Best Seller

60 Lectures 8 hours

To create a cumulative sum plot in base R, we can simply use plot function. For cumulative sums inside the plot, the cumsum function needs to be used for the variable that has to be summed up with cumulation. For example, if we have two vectors say x and y then the plot with cumulative sum plot can be created as plot(x,cumsum(y)).

## Example

x1<--10:10
y1<-rnorm(21,5,0.324)
plot(x1,cumsum(y1))

## Example

x2<-1:20
y2<-rpois(20,5)
plot(x2,cumsum(y2))

## Output

Updated on 08-Feb-2021 05:11:00