0

I have this plot and I would like to have the bars in reverse order (flying, poison,..., dark, bug). I've tried some of the solutions here and so far I can only sort them in this order.

This is the data

> bug_dual_type
dataset.Type.1 dataset.Type.2 Freq
1              Bug            Bug    0
19             Bug           Dark    0
37             Bug         Dragon    0
55             Bug       Electric    2
73             Bug          Fairy    0
91             Bug       Fighting    1
109            Bug           Fire    2
127            Bug         Flying   13
145            Bug          Ghost    1
163            Bug          Grass    6
181            Bug         Ground    1
199            Bug            Ice    0
217            Bug         Normal    0
235            Bug         Poison   11
253            Bug        Psychic    0
271            Bug           Rock    3
289            Bug          Steel    5
307            Bug          Water    1

This is my code:

bug_dual_type<-types_table_complete[types_table_complete$dataset.Type.1 == "Bug", ]
bug_dual_type
bug_dual_type$ordered_Levels <- reorder(bug_dual_type$dataset.Type.2, (bug_dual_type$Freq))
ggplot(bug_dual_type,aes(x=(ordered_Levels), y = Freq)) + geom_bar(binwidth=1, stat="identity", fill="#E69F00")

And the plot: enter image description here

Thanks.

user3276768
  • 1,416
  • 3
  • 18
  • 28
  • In your code, you reorder by `bug_dual_type$Freq`. To reverse the order, change that to`-bug_dual_type$Freq` to make it negative. – Gregor Thomas Mar 19 '15 at 22:16
  • Try `... (x=reorder(ordered_Levels, desc(Freq))...`. <- you can use this method to order the `x` axis by the `y` values, without having to order the data outside of the plot – tospig Mar 19 '15 at 22:21
  • Thanks for the solutions guys. Gregor, I used yours and it worked. – user3276768 Mar 19 '15 at 22:40
  • I blogged about the terms "order" and "plot" in the same sentence: https://trinkerrstuff.wordpress.com/2012/10/15/how-do-i-re-arrange-ordering-a-plot/ – Tyler Rinker Mar 19 '15 at 23:17

0 Answers0