[R] Barchart reorder

Gabor Grothendieck ggrothendieck at gmail.com
Sat May 15 16:46:30 CEST 2010


Reorder it based on the negative of abundance to reverse it:
reorder(table$species, - table$abundance)

On Sat, May 15, 2010 at 6:40 AM, Kang Min <ngokangmin at gmail.com> wrote:
> Hi fellow R users,
>
> I have a dataset that looks something like this.
>
> species class   abundance
> K       1       592
> K       2       288
> G       1       254
> G       2       239
> C       2       173
> D       2       123
> E       3       89
> F       2       87
> B       2       86
> H       2       82
> I       1       79
> J       2       76
> B       1       73
> D       3       72
> A       2       62
> L       2       58
>
> I want to plot a stacked barchart. species is the x-axis, abundance is
> y-axis, and class will appear as the stacks in different colours. I
> need the species to be displayed in descending order of abundance,
> meaning species K on the left side of the graph to species L on the
> right.
>
> I've read other posts here that recommended the function reorder,
> which I've used but species K appears on the right side of the graph
> instead.
>
> barchart(table$abundance ~ reorder(table$species, table$abundance),
>           groups = table$class, stack = T, scales = list(x = list(draw =
> F)),
>           auto.key = list(adj = 1))
>
> Is there anything wrong with my code?
>
> Thanks.
> Kang Min
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list