-1

I have a data frame df1 and want to draw a barplot of AccountExecutive and their corresponding ClearRate where the bars are arranged so that it is decreasing from left to right.

I tried this code but the resulting graph still reflects AccountExecutive order as it appears in df1

ggplot(arrange(df1, -ClearRate), aes(x = AccountExecutive, y = ClearRate)) +
  geom_bar(stat="identity")

Can anyone help me correcting this code?

NOTE: Not a duplicate of the previous question because that one asks for an arbitrary positioning of the x axis labels. This question asks how to sort x-axis labels considering their y-axis values.

  • So I used this code 'ggplot(df1, aes(x = fct_infreq(AccountExecutive), y = ClearRate)) + geom_bar(stat="identity", aes(fill=Area)) + theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5))' but it still doesn't work. – Angelo Louise Lopez Feb 12 '17 at 09:17
  • As we can't see what's on your screen: What do you mean "it still doesn't work". Please, provide a [mcve]. Thank you. – Uwe Feb 12 '17 at 09:45
  • If you are using `geom_bar(stat="identity")` you probably do have a frequency table already. Then you probably need to use `forcats::fct_reorder(AccountExecutive, ClearRate)`. However, this is only a shot in the dark as you haven't provided a [mcve]. – Uwe Feb 12 '17 at 09:51
  • I think you got it correctly. It is now working. Thanks Nonetheless – Angelo Louise Lopez Feb 12 '17 at 10:03

1 Answers1

2

Try this one the code below should reorder AE according to clearance rate

ggplot(df1,aes(x=reorder(AccountExecutive,-ClearRate),y=ClearRate))+geom_bar(stat"identity")

here is the more about reorder function Reorder bars in geom_bar ggplot2

Community
  • 1
  • 1
Biranjan
  • 303
  • 3
  • 12