Given a two column data frame with a categorical column of labels and a quantitative column of percent data, I can reliably produce a bar chart in ggplot that sorts the bars by value rather than by alphabetical order using the following:
ggplot(data=df, aes(x=reorder(Label, Percent), y=Percent, fill=Label)) + geom_bar()
This tells reorder to sorts the bar chart by the percent value rather than the text, making it easier to see the changes.
I cannot, however, get the legend to match: instead it persists in being sorted by the original alphabetical values. This results in a legend which doesn't match the chart, which is confusing.
I've looked on StackOverflow and elsewhere, and haven't found a fix that will work. Any advice?
Edit: per requests, this is essentially the data:
Labels <- c("G", "G", "A", "C", "M", "B", "M", "G", "A","M")
Percent <- c("-0.241","-0.046", "-0.037", "-0.024", "-0.003","0.007","0.01","0.059","0.121", "0.152")