[R] Boxplot Help: Re-ordering the x-axis
Marc Schwartz (via MN)
mschwartz at mn.rr.com
Thu Aug 17 21:03:07 CEST 2006
On Thu, 2006-08-17 at 11:46 -0700, Pamela Allen wrote:
> I am having a problem using boxlpot with my data. I have my data arranged
> in a data table, and two of my columns are "mass" and "month". I am trying
> to plot the mass of my study animals by month, thus I would like to have it
> in the order of January to December. The problem is that R orders each
> month in alphabetical order, and gives each month an integer value
> corresponding to this (i.e. April is integer=1, August=2, September=12). I
> have tried many different ways to solve this but nothing is working. If
> anyone knows how to order the x-axis in boxplot, or alternatively, re-assign
> integer values to each month that would be very helpful. Thank you in
> advance!
Note the following in the Details section of ?boxplot:
"If multiple groups are supplied either as multiple arguments or via a
formula, parallel boxplots will be plotted, in the order of the
arguments or the order of the levels of the factor (see factor)."
If you are using a formula approach, then something like the following:
month <- factor(month,
levels = c("January", "February",
...,
"November", "December")
boxplot(mass ~ month)
See ?factor
For future reference, using:
> RSiteSearch("boxplot order")
will search the r-help archive using the indicated key words, where you
will see that this has been covered previously.
HTH,
Marc Schwartz
More information about the R-help
mailing list