This is working perfectly now…thanks a lot for your help.


On 27/03/2013, at 2:36 AM, "Law, Jason" <jason....@portlandoregon.gov> wrote:

> Try this:
> 
> library(plyr)
> library(ggplot2)
> library(lubridate)
> data<-read.csv("http://dl.dropbox.com/u/4236038/test_cumu.csv";)
> data$Date <- as.Date(data$Date)
> cumu <- ddply(data,.(year(Date)),transform, cumRain = cumsum(Rainfall))
> ggplot(cumu, aes(x = yday(Date), y = cumRain, color = factor(year(Date)))) + 
> geom_line()
> 
> You'll have to work on the date axis.
> 
> Jason Law
> Statistician
> City of Portland, Bureau of Environmental Services
> Water Pollution Control Laboratory
> 6543 N Burlington Avenue
> Portland, OR 97203-5452
> 503-823-1038
> jason....@portlandoregon.gov
> 
> 
> -----Original Message-----
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of Martin Labadz
> Sent: Monday, March 25, 2013 10:44 PM
> To: r-help@r-project.org
> Subject: [R] Plot cumulative sums of rainfall per year
> 
> Hi @all,
> 
> I am biting my nails with the following problem:
> 
> I have a data set of daily rainfall measurements for the last 20 years. What 
> I want to do is calculate the daily cumulative sum of rainfall but only for 
> every year which means that the cumulative sum has to be reset each year. 
> After the calculations I want to plot each year of cumulative rainfall as a 
> separate line in one graph preferably using ggplot with the x-axis showing 
> the julian day 1 to 365 (366) and the y-axis showing the cumulative values.
> 
> I have the following code:
> 
> library(plyr)
> library(ggplot2)
> data<-read.csv("http://dl.dropbox.com/u/4236038/test_cumu.csv";)
> data$year <- as.numeric(format(as.Date(data$Date), format="%Y")) 
> ddply(data,.(year),transform,cumRain = cumsum(Rainfall))->cumu ggplot(cumu, 
> aes(Date,cumRain))+geom_point()
> 
> What it does it perfectly calculates the cumulative sum of the rainfall and 
> resets the sum at the beginning of each year but I cannot plot the cumulative 
> sum of rainfall in a way that each year is represented by a separate line in 
> one graph such as in this example: 
> http://dl.dropbox.com/u/4236038/example_cumulative_rainfall.png
> 
> Any help would be highly appreciated.
> 
> Thanks,
> Martin
> 
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to