Hello there,
Consider this simple example
library(tibble)
library(ggplot2)
library(dplyr)
tibble(group = c(1,1,1,1,2,2,2,2),
label = c('a','b','c','d','e','f','a','b'),
value = c(10,9,8,7,20,2,12,1)) %>%
ggplot(aes(x = as.factor(label), y = value, fill = as.factor(group))) +
geom_bar(stat = 'identity') + coord_flip() +
facet_wrap(~ as.factor(group))
My problem is that I would like EACH facet to be sorted from the label with the highest value to the label to the lowest value. For instance in group 1
the highest label is a
, while in group 2
its e
.
How can I do that?
Thanks!