I have this sample dataset in R:
What I would like to do is create a running total of the payment amount, separated into different series by the Rainforest.Segment
factor. I have ordered the dataset by the dateofpayment
What I have is: ggplot(dataset, aes(x=dateofpayment, y=cumsum(PAYMENTAMOUNT), colour=Rainforest.Segment, group=Rainforest.Segment)) + geom_line()
I get what looks like the correct plot, but the cumulative sum is quite clearly incorrect (I know that the cumulative sum for each segment is < $50,000):
Could someone please give me some advice on what could be going wrong - and how to correct the issue?
Thanks so much!