Question

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

Était-ce utile?

La solution

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

plot(day, cumsum(rain_1951)/sum(rain_1951))
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top