[R] ordering a boxplot

David Winsemius dwinsemius at comcast.net
Sat Mar 21 18:43:08 CET 2015


On Mar 20, 2015, at 2:20 PM, Antonio Silva wrote:

> Hello
> 
> I'm using a dataframe (mydata) where row names are sampling points and
> column names are species in a multivariate analysis.
> 
> If I write boxplot(mydata) I'll have boxplots for each species abundance in
> alphabetical order.
> 
> How to get the boxes orderer by the median?
> 
> Usually for this I write
> boxplot(value~category,at=rank(tapply(mydata$value,mydata$category,median)))

I would not have expected that to succeed. The usual approach is to change the order of factor levels before the call to boxplot.


> but for this to work I need a column for the categories and another column
> for the values.

Yes. That is the usual situation. Since you provide no data we cannot tell what is different about your case.

> 
> Thanks in advance, best regards.
> 
> Antonio Olinto
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list