-4

I want to plot a percentage cumulative graph of rainfall against day (time of the year). For example my data is:

     day      rain
     1        12.2
     2        32.5
     3        23.4  
     4        33.9
     5        19.8
     6        15.3
     7        16.8

and I want something like this:

   day      rain        cumulative
     1        12.2          12.2
     2        32.5          12.2+32.5
     3        23.4          12.2+32.5+23.4
     4        33.9          12.2+32.5+23.4+33.9
     5        19.8          12.2+32.5+23.4+33.9+19.8 
     6        15.3          15.3+12.2+32.5+23.4+33.9+19.8 

I have produced a cumulative plot but this gives me the absolute cumulative graph.

plot(day,cumsum(rain_1951))

I need to produce the same in terms of percentage cumulative graph i.e. each item in cumulative is divided by total(rain).

Any suggestions Thanks

89_Simple
  • 3,393
  • 3
  • 39
  • 94
  • 2
    Please read the info about how to [ask a question](http://stackoverflow.com/help/how-to-ask) and how to produce a [minimal reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) – Jaap May 15 '14 at 14:22
  • 7
    I suggest you use division. – joran May 15 '14 at 14:28
  • 3
    What joran means, in case it isn't clear to you, is that `plot(day, cumsum(rain_1951)/sum(rain_1951))` will give you the plot you seem to be wanting. – Josh O'Brien May 15 '14 at 15:15

1 Answers1

3

To get percentages, you just need to divide by the total:

plot(day, cumsum(rain_1951)/sum(rain_1951))
MrFlick
  • 195,160
  • 17
  • 277
  • 295