Skip to content

monthly boxplot

8 messages · David Winsemius, Carlos Ortega, Fernando Andreacci +1 more

#
On Aug 9, 2011, at 9:46 AM, Fernando Andreacci wrote:

            
By converting those character strings to dates. At the moment you seem  
to believe that R has the ability to "know" that you want these  
strings to be dates.

?as.Date
?Dates
#
On Aug 9, 2011, at 10:17 AM, Fernando Andreacci wrote:

            
You have not shown us how you set the data up or made the boxplots. A  
"trend line through boxplots" seems be a bit ambiguous, since the x- 
variable needs to be a factor and  a factor variable would not  
necessarily have either a scale or an order. So the answer with the  
available information cannot be anymore specific than "it depends".
#
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)