On Thu, Jul 7, 2011 at 5:41 AM, Dr Eberhard Lisse <e...@lisse.na> wrote: > Hi, > > I am reading payment data like so > > 2010-01-01,100.00 > 2010-01-04,100.00 > ... > 2011-01-01,200.00 > 2011-01-07,100.00 > > and plot it aggregated per month like so > > library(zoo) > df <- read.csv("daily.csv", colClasses=c(d="Date",s="numeric")) > z <- zoo(df$s, df$d) > z.mo <- aggregate(z, as.yearmon, sum) > barplot(z.mo, col="darkblue") > > How do I get the monthly aggregated payments in different colors > next to each other (ie for each year in a different color with the x > axis showing the months)? >
Read it in with read.zoo aggregating at the same time to yearmon class and then issue the appropriate lattice barchart command: Lines <- "Date,Value 2010-01-01,100.00 2010-01-04,100.00 2010-02-04,100.00 2011-01-01,200.00 2011-01-07,100.00 2011-02-07,100.00" library(zoo) z <- read.zoo(textConnection(Lines), header = TRUE, sep = ",", FUN = as.yearmon, aggregate = sum) library(lattice) year <- factor(as.numeric(floor(time(z)))) value <- coredata(z) month <- coredata(cycle(z)) barchart(value ~ month | year, horiz = FALSE, col = 1:12, origin = 0) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ 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.