[R] Sorting problem

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Dec 24 12:17:46 CET 2004


On Fri, 24 Dec 2004, Paul JH Drake wrote:

> I'm using R 2.0 in SuSE 9.2.

There is no such version, BTW: please see the posting guide for hints on 
supplying the sort of information we need (and an example would have 
helped a lot here).

> When I plot data as a boxplot, the boxes appear on the plot in
> alphabetical order (of group) rather than the order in which they appear
> in the data.

I'm guessing you used the formula interface to boxplot(): if so they 
appear in the order of the levels of the factor.  Otherwise they appear in 
the order the groups are supplied to boxplot().

> So far, the only thing I can do to fix this is to prefix the group 
> labels with a,b,c...etc to trick R into plotting them in the right 
> order.
>
> Can sorting be turned off?

No, as it is not turned on!

> How should I address this sensibly?

I need to be guessing, again!  Create your group as a factor with the 
levels in the order you want.  You don't tell us how you created it, but 
see ?factor.  In particular, if you did not supply a factor but something 
which was coerced to a factor, supply a factor.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list