Skip to content
Prev 303437 / 398503 Next

boxplot help

Okay your first main problem is that you have Year and Month as character variables.

I think you need to convert them to a single date: Try this:
eagle$dates  <-  as.Date(paste(dd, "/", "01", sep=""), "%Y/%b/%d")

I think this helps cure a lot of the problem.

However a different approach to the same results I think is this using the ggplot2 package which I imagine you would have to install ( install.packages("ggplot2") 

I noticed that your dput() example only had data for a part of one year so I manufactored some data to use as an example.  However you still need to create the dates column.  




# Data Set

mydat <- structure(list(roof = structure(c(1L, 3L, 2L, 1L, 1L, 2L, 3L, 
3L, 3L, 1L, 1L, 1L, 3L, 1L, 1L, 2L, 3L, 1L, 1L, 1L, 1L, 1L, 3L, 
1L, 3L, 1L, 3L, 3L, 3L, 3L, 2L, 2L, 3L, 1L, 2L, 3L, 2L, 1L, 2L, 
3L, 3L, 1L, 1L, 3L, 3L, 1L, 3L, 2L, 3L, 2L), .Label = c("bare", 
"tt13", "tt6"), class = "factor"), dates = structure(c(8L, 8L, 
3L, 3L, 8L, 9L, 5L, 7L, 11L, 1L, 11L, 12L, 7L, 12L, 3L, 4L, 2L, 
2L, 9L, 6L, 6L, 6L, 11L, 12L, 4L, 1L, 3L, 12L, 5L, 2L, 9L, 10L, 
11L, 6L, 1L, 11L, 5L, 9L, 4L, 9L, 9L, 2L, 12L, 1L, 11L, 9L, 2L, 
9L, 4L, 6L), .Label = c("2011-06-01", "2011-07-01", "2011-08-01", 
"2011-09-01", "2011-10-01", "2011-11-01", "2011-12-01", "2012-01-01", 
"2012-02-01", "2012-03-01", "2012-04-01", "2012-05-01"), class = "factor"), 
    temp = c(17.33, 16.92, 17.06, 17.79, 17.63, 5.16, 13.85, 
    14.3, 14.44, 11.32, 15.15, 15.04, 17.72, 10.33, 10.46, 9.25, 
    10.7, 13.72, 19.2, 9.03, 8.69, 13.41, 16.08, 19.91, 10.87, 
    14.06, 16.57, 8.66, 17.74, 15.71, 17.91, 7.26, 15.89, 22.14, 
    15.93, 20.01, 18.45, 12.34, 15.67, 13.7, 10.68, 7.2, 16.83, 
    13.99, 14.69, 16.13, 20.35, 16.89, 19.34, 15.05), year = c(2012L, 
    2012L, 2011L, 2011L, 2012L, 2012L, 2011L, 2011L, 2012L, 2011L, 
    2012L, 2012L, 2011L, 2012L, 2011L, 2011L, 2011L, 2011L, 2012L, 
    2011L, 2011L, 2011L, 2012L, 2012L, 2011L, 2011L, 2011L, 2012L, 
    2011L, 2011L, 2012L, 2012L, 2012L, 2011L, 2011L, 2012L, 2011L, 
    2012L, 2011L, 2012L, 2012L, 2011L, 2012L, 2011L, 2012L, 2012L, 
    2011L, 2012L, 2011L, 2011L)), .Names = c("roof", "dates", 
"temp", "year"), class = "data.frame", row.names = c(NA, -50L
))


# Then give this a try. It looks a bit weird as I just generated a bunch of dates.
#=================================================
library(ggplot2)
p  <-  ggplot( mydat , aes(as.factor(dates) , temp, fill = factor(roof))) + geom_boxplot(statistic = "identity") + 
           ylab("Temperature") + xlab("Months")  + scale_fill_hue(name="Roof\nType")  +
            facet_grid( year ~ .)
p

# ===================================================

John Kane
Kingston ON Canada
____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!