I want to reorder a geom_bar graph from high to low when using stat="count" so that I can apply a fill.
I tried using geom_bar(aes(x = reorder(x, -stat(count)), fill = type) but it didn't work and threw the error "Error: stat_count requires the following missing aesthetics: x"
library(ggplot2)
df <- data.frame(x = c("Bob", "James", "Mary", "Sally", "Timmy", "Sally", "Sally", "Bob", "Bob", "Mary"), type = c("A", "B", "A", "B", "B", "C", "B", "B", "A", "B"))
ggplot(df) +
geom_bar(aes(x = x, fill = type), stat = "count") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5))
I want the bars to be order from highest count on the left to lowest count on the right.