0

I have been searching for a solution to order my bars in a bar chart in descending order. I have seen the "reorder" function for example. However, my y-values (so the counts for all my x-values) is not counted beforehand. However, I use the stat="count" function in aes.

Here is the code I use to plot:

ggplot(data[correctAnswer==3&conditionTemp=="uni"], aes(x=colorAnswers)) +
   geom_bar(aes(stat = "count"), width=0.6, color = "black", fill="blueviolet")+theme_classic()

Currently the bars are ordered alphabetically (My x-values are categories such as "black", "white" etc).

Is there a way to order them, without counting assurances beforehand and creating a new columnn or summarised data frame?

Thanks!

Ella
  • 15
  • 2
  • You can easily calculate the counts ahead of time using `dplyr` or something. It's better to take control of your data summarization and just allow ggplot to take care of the plotting. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Feb 24 '22 at 18:45

0 Answers0