Ordering of bars in ggplot

前端 未结 1 916
生来不讨喜
生来不讨喜 2020-12-07 16:54

I have looked through the answers in this forum but cannot seem to find an answer to this specific problem. I have the following data and want to create a bar chart where th

相关标签:
1条回答
  • 2020-12-07 17:18

    You want function reorder():

    breadth_data <- transform(breadth_data, 
                              Stakeholder = reorder(Stakeholder, Value))
    

    Which gives:

    reordered barplot

    If you want them the other way round, an easy way is just to use order() on Value inside the reorder() call:

    breadth_data <- transform(breadth_data,
                              Stakeholder = reorder(Stakeholder, 
                                                    order(Value, decreasing = TRUE)))
    
    0 讨论(0)
提交回复
热议问题