Here is my example:
set.seed(1)
x <- replicate(n = 5, 'left')
y <- replicate(n = 5, 'right')
dir <- c(x,y)
quantity <- sample(seq(1,100), 10)
names <- rep(letters[1:5],2)
tb <- tibble(dir,quantity,names) %>%
group_by(dir) %>%
arrange(desc(quantity))
tb %>%
ggplot(aes(x = fct_inorder(names), quantity)) +
geom_bar(stat = 'identity', color = 'black') +
coord_flip() +
facet_wrap(~dir, scales = "free")
What I would like is to have both the left and right reorder the x-axis by descending order of quantity.


To reorder the facets individually you could (have to) use a helper column, i.e. the interaction of your
yaxis variable and the variable you facet by. Then reorder your data in your desired order (as you already did) and afterwards set the order of the helper column according to the order of the data usingfct_inorder. Finally, map the helper column onyand clean up the labels, i.e. remove the part of label corresponding to the facetting variable.Note: You might also have a look at the
tidytextpackage which provides convenience functionsreorder_withinandscale_x/y_reorderedto achieve the same result using the same approach under the hood.