Skip to content
Prev 268106 / 398502 Next

monthly boxplot

On 8/9/2011 10:32 AM, Fernando Andreacci wrote:
Make the "date" variable a factor with the right format and the levels 
in chronological order:

vardates <- c("10/1/2010", "10/1/2010", "10/1/2010", "10/1/2010",
	"10/1/2010", "10/1/2010", "10/1/2010", "10/1/2010", "10/1/2010",
	"11/1/2010", "11/1/2010", "11/1/2010", "11/1/2010", "11/1/2010",
	"11/1/2010", "11/1/2010", "11/1/2010", "11/1/2010", "12/1/2010",
	"12/1/2010", "12/1/2010", "12/1/2010", "12/1/2010", "12/1/2010")
varmeasure <- c(0.0, 26.0,  0.2, -0.2, -1.2, -0.8,  0.0,  4.4, -0.6,
	0.2, 14.4, -0.2, 4.8, 4.0, 2.8, 3.2, 3.8, 3.2, -11.4, 0.2, 0.4,
	3.0, 0.6, 6.2)

vardates <- as.Date(vardates, format="%m/%d/%Y")
vardates.fmt <- factor(strftime(vardates, format="%m/%Y"),
	levels=strftime(sort(unique(vardates)), format="%m/%Y"))

boxplot(varmeasure ~ vardates)
boxplot(varmeasure ~ vardates.fmt)