Plot monthly time series with zoo in R -


i have daily time series read in zoo , aggregate time series month compute mean:

# ts original daily time series # ts zoo  m = aggregate(ts, by=months, mean) 

the aggregated date m looks (the values fabricated):

april  august  december  february  january  july   40      80       120     20        10       70    june  march  may  november  october  september     60    30     50   110       100      90   # check class of index > class(index(m)) [1] "character"  # subsetting manually > m[c('january', 'december'] [1] december  january      120       10 

obviously, index of m sorted character internally, makes line chart difficult read.

how sort aggregated time series m month?

assuming input shown:

library(zoo) ts <- zoo(1:12, as.date(as.yearmon(2000) + 0:11/12))  aggregate(ts, = match(months(index(ts)), month.name), mean) 

note month.name built r.

please make sure questions reproducible. input in question missing.


Comments