[R] reversing the x-axis terms on a boxplot
sundar.dorai-raj at pdf.com
Wed Jul 25 21:05:21 CEST 2007
Dylan Beaudette said the following on 7/25/2007 11:18 AM:
> I am able to reverse the order of plotting on regular plots (i.e. with the
> plot() function) by manually setting the xlim variable.
> Is there some trick like this which will work for a boxplot?
> * for example:
> l <- sample(letters, 500, replace=TRUE)
> n <- runif(500)
> boxplot(n ~ l)
> this will produce a plot with the x-axis ranging from a->z ... i know that
> these are labels, associated with an integer index-- but is there someway to
> reverse the plotting order?
> Thanks in advance,
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
l <- sample(letters, 500, replace=TRUE)
n <- runif(500)
l <- factor(l, levels = rev(letters))
boxplot(n ~ l)
This is explained 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
This means you can create any order you want by setting the factor
More information about the R-help