[R] Alphabetical sequence of data along the x-axis in a box plot

Joshua Wiley jwiley.psych at gmail.com
Mon Sep 27 22:16:36 CEST 2010


Hi Eddie,

I've been on a role with the iris data, so I figure why stop.
Assuming that one variable is a factor, you can easily reverse it, and
if you want fine tuned control, then just reorder the levels.  Here is
an example:

dat <- iris
boxplot(Sepal.Length ~ Species, data = dat)
boxplot(Sepal.Length ~ rev(Species), data = dat)
# They had been ordered alphabetically, now I am changing them
dat$Species <- factor(dat$Species, levels = c("versicolor",
"virginica", "setosa"),
  labels = c("versicolor", "virginica", "setosa"))
boxplot(Sepal.Length ~ Species, data = dat)

Cheers,

Josh

On Mon, Sep 27, 2010 at 12:59 PM, Hughes, Ed <ehughes at conshelf.com> wrote:
> Hello All,
>
>
>
> I noticed when I generated some boxplots, the data is presented in
> alphabetical order along the x-axis (the data in this case was the four
> quandrants of a sample area (NE,NW, SE, SW) that was my first column of
> data).  Is there a way to have R plot the data in a different order?  I
> imagine you could use a dummy variable, but didn't know if there might
> be a simple argument  that will address this?
>
>
>
> Thanks for any guidance,
>
> Eddie Hughes
>
>
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list