Problem
My question is very simple, but apparently unanswered. I have a count barplot and I simply want to order the bars based on their count. However 1. I don't want to modify the original dataframe, that is unnecessary, and in more complicated examples it would be way too long to do. 2. I don't want to change the order without changing the actual underlying order of the labels. In the MWE below, for instance, I dont want to change the genres that artists belong to (which is what literally every other answer on StackOverflow suggests to do).
Minimal Working Example
library(ggplot2)
# Create data
df <- data.frame(genre=c("Pop", "HipHop", "Latin", "Pop", "Pop", "HipHop"), artist=c("ArianaGrande", "ChrisBrown", "DaddyYankee", "EdSheeran", "LewisCapaldi", "ShawnMendes"))
# Plot
ggplot(data=df) +
geom_bar(aes(x=genre, fill=artist))
How do I order the bars, keeping everything else the same? Surely this should happen at the plot level, not at the dataframe level, nor at the "input" level of ggplot.