I've seen a number of solutions on StackOverflow of this sort but I'm not sure what the best solution is to sort a categorical variable (default is alphabetical) based on a continuous variable.
Following is a simple example of this idea.
library(tidyverse)
data <- data.frame(Name = c('b','a','c'), Value = c(1,2,3))
g <- data %>%
ggplot(aes(Name, Value)) + geom_col()
g
I came across the following solution and this has been my favorite thus far, as it makes the most sense to me.
g <- data %>%
ggplot(aes(reorder(Name, Value), Value)) +
geom_col() +
labs(x = "Name",y="Value")
g
How does the community generally go about doing this?