[R] ggplot2 month and year boxplot x axis order problem

stephen sefick ssefick at gmail.com
Fri Jun 24 19:57:52 CEST 2011


This needs to be made reproducible.  In other words it would be
helpful if you would use dput to share the data.

dput(Good)

copy the output to the email in this format

x  <- ()

with the output from dput inside the ()

then write the code for ggplot under this line so that we can then
just modify things to make it work.

On Fri, Jun 24, 2011 at 11:52 AM, philipharrison <pharriso at uwaterloo.ca> wrote:
> Hi
>
> I am very new to R, I am attempting to produce a monthly boxplot with the
> following fish thermal telemetry data:
>
>    ID   Temp        Date.Time Month.Year Month Week  Shortdate
> 1 1734 4.4140 04/05/2010 11:56    05,2010   May   19 04/05/2010
> 2 1734 4.1002 04/05/2010 12:06    05,2010   May   19 04/05/2010
> 3 1734 3.9433 04/05/2010 12:09    05,2010   May   19 04/05/2010
> 4 1734 3.6295 04/05/2010 12:29    05,2010   May   19 04/05/2010
> 5 1734 3.6295 04/05/2010 12:34    05,2010   May   19 04/05/2010
> 6 1734 3.6295 04/05/2010 12:37    05,2010   May   19 04/05/2010
>
> I constructed my data in access. I have data from May2010 to april 2011
>
> When I use ggplot2
>
> plot6<-ggplot(data=Good,aes(Month.Year,Temp))
>> + geom_boxplot()
>
> the x axis factor order is jan 2011,feb2011, march 2011, april2011, May
> 2010etc. I would like the months to be in chronological order
>
> I have tried a number of conversions using format and as.date and as.POSIXlt
> with no luck including
>
> Goodyearmonth<-as.Date(Good$Shortdate,format="%Y/%m")
>
> and i tried
>
> Good$Gmonth<- with(Good,factor(as.POSIXlt(Shortdate)$mon)
>
> If I pivot my data by month in access so it looks like this
> May-10  Jun-10  Jul-10
> 4.1002  7.3951  8.3365
> 3.9433  7.3951  8.1796
> 3.6295  7.3951  8.0227
>
> then a simple boxplot() works however I would like to use the ggplot2
> package because eventually I would like to change the whiskers to 95% and 5%
> quantiles (I think I know how to do this
> http://r.789695.n4.nabble.com/Custom-Plot-means-SD-amp-5th-95th-Plotmeans-or-Boxplot-td848126.html)
>
> Thanks for any help you can provide
>
> Philip Harrison
> PhD Student Fisheries ecology
> Uwaterloo
>
> --
> View this message in context: http://r.789695.n4.nabble.com/ggplot2-month-and-year-boxplot-x-axis-order-problem-tp3623029p3623029.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Stephen Sefick
____________________________________
| Auburn University                                         |
| Biological Sciences                                      |
| 331 Funchess Hall                                       |
| Auburn, Alabama                                         |
| 36849                                                           |
|___________________________________|
| sas0025 at auburn.edu                                  |
| http://www.auburn.edu/~sas0025                 |
|___________________________________|

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

                                -K. Mullis

"A big computer, a complex algorithm and a long time does not equal science."

                              -Robert Gentleman



More information about the R-help mailing list