0

I'm having trouble reordering the bars in this bar chart. Here is my code:

ggplot(Issues103, aes(IssueNew)) + 
  geom_bar(aes(y = (..count..)/sum(..count..))) + 
  geom_text(aes(y = ((..count..)/sum(..count..)), 
                label = scales::percent((..count..)/sum(..count..))), 
            stat = "count", vjust = -0.25, size = 3.2) + 
  scale_y_continuous(labels=scales::percent) + 
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) + 
  labs(title = "Issues Discussed in WIR Speeches: 103rd Congress", x = "Issue", y = "Percentage of WIR Speeches") 

This gets me:

enter image description here

I'd like to reorder the bars by percentage in descending order. I've looked everywhere, but I can't figure out how to do this when y = (..count..)/sum(..count..).

I'm very new to all of this, so thanks for the help!

CWin
  • 9
  • 2
  • Look at this link: https://stackoverflow.com/questions/30633741/ggplot2-cant-sort-x-axis-by-y-value – iRhonin May 01 '18 at 15:12
  • 1
    The answer to this question is always [this](https://stackoverflow.com/questions/5208679/order-bars-in-ggplot2-bar-graph?rq=1). The problem is that people sometimes struggle to create a suitable factor with the levels in the proper order. I'm guessing that's the sticking point here? – joran May 01 '18 at 15:15
  • @joran That worked. Not sure why I didn't find that earlier. Thank you! – CWin May 01 '18 at 15:25
  • Excellent! It can be hard finding the right question sometimes. Based on your comment, I'm going to point this question to the one I linked to as a duplicate so other people can be pointed in the same direction. – joran May 01 '18 at 15:28

0 Answers0