I'd like to make a plot showing frequency of an event. The data is in a data from that includes Year, Month and Day (of month) fields, so I created a Date with ISOdate(Year, Month, Day, tz=''). I can plot frequencies for the year 2002 with > thisyear <- Date[Year==2002] > hist( thisyear, xaxt='n' ) > axis.POSIXct( 1, at=seq(min(thisyear), max(thisyear), by="month"), format='%b %Y' ) Now I want to specify the histogram breaks so that there is one bin per month, so I tried this: > hist( thisyear, breaks=ISOdate( rep(2002,12), seq(12), rep(1,12), tz='' ), xaxt='n' ) That resulted in an error message that said: Error in Ops.POSIXt(1e-07, mean(h)) : * not defined for POSIXt objects Can anyone suggest a way to do this? Or another method for plotting this sort of month by month frequency plot? For a single year I could histogram the month, but I'd like to be able to span any date range, including multiple years. Mike -- Michael A. Miller mmiller3 at iupui.edu Imaging Sciences, Department of Radiology, IU School of Medicine -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
One way would be to convert to POSIXlt and extract the month element. Then you should be able to tabulate the number of events in each month, and make a barplot of those. -Don At 4:57 PM -0500 5/28/02, Michael A. Miller wrote:>I'd like to make a plot showing frequency of an event. The data >is in a data from that includes Year, Month and Day (of month) >fields, so I created a Date with ISOdate(Year, Month, Day, >tz=''). I can plot frequencies for the year 2002 with > > > thisyear <- Date[Year==2002] > > hist( thisyear, xaxt='n' ) > > axis.POSIXct( 1, at=seq(min(thisyear), max(thisyear), by="month"), > format='%b %Y' ) > >Now I want to specify the histogram breaks so that there is one >bin per month, so I tried this: > > > hist( thisyear, > breaks=ISOdate( rep(2002,12), seq(12), rep(1,12), tz='' ), > xaxt='n' ) > >That resulted in an error message that said: > > Error in Ops.POSIXt(1e-07, mean(h)) : * not defined for POSIXt objects > >Can anyone suggest a way to do this? Or another method for >plotting this sort of month by month frequency plot? For a >single year I could histogram the month, but I'd like to be able >to span any date range, including multiple years. > >Mike > >-- >Michael A. Miller mmiller3 at iupui.edu > Imaging Sciences, Department of Radiology, IU School of Medicine >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- >r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html >Send "info", "help", or "[un]subscribe" >(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch >_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thanks for all the suggestions. After fiddling alonw the lines of your suggestions, I found a solution in the examples in hist.POSIXt: hist(thisyear, breaks=seq(ISOdate(2000,1,1),ISOdate(2003,1,1),by='month')) hist(thisyear, breaks=seq(ISOdate(2000,1,1),ISOdate(2003,1,1),by='week')) Thanks! Mike -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._