I want to produce seasonal boxplots for a lot of different time series. I hope that the code below clearly illustrates what I want to do.
My question is now, how to
You are better off picking out the month names directly with the "%b"
format and using an ordered factor and the formula interface for boxplot
:
DF$month <- factor(strftime(DF$Time,"%b"),levels=month.abb)
boxplot(Data~month,DF)
Using 'ggplot2' (and @James' month names, thanks!):
DF$month <- factor(strftime(DF$Time,"%b"),levels=month.abb)
ggplot(DF, aes(x=,month, y=Data)) +
geom_boxplot()
(BTW: note that in 'ggplot2' "The upper and lower "hinges" correspond to the first and third quartiles (the 25th and 7th percentiles). This differs slightly from the method used by the boxplot function, and may be apparent with small samples." - see documentation)
To set months as ordered factor in any locale settings use a trick which can be found in help page for ?month.abb
:
Sys.setlocale("LC_TIME", "German_Germany")
DF$month <- factor(format(DF$Time, "%b"), levels=format(ISOdate(2000, 1:12, 1), "%b"))
And you could plot it in lattice
as well:
require(lattice)
bwplot(Data~month, DF, pch="|") # set pch to nice line instead of point