Sort order of box obtained from geom_boxplot
Arguments
- x
 ggplot2 with atleast one layer of geom_boxplot
- decreasing
 logical, default TRUE, indicating whether the box are arraged in increasing or decreasing order.
Examples
library(ggplot2)
dd <- iris %>%
  tidyr::pivot_longer(cols = Sepal.Length:Petal.Width)
# single layer
ss <- dd %>%
  ggplot2::ggplot() +
  geom_boxplot(aes(x = name, y = value))
sort_geom_box(x = ss,decreasing = TRUE)
sort_geom_box(x = ss,decreasing = FALSE)
# multiple layer
ss <- dd %>%
  ggplot2::ggplot() +
  geom_point(aes(y = value , x = name)) +
  geom_boxplot(aes(x = name, y = value))
sort_geom_box(x = ss,decreasing = TRUE)
sort_geom_box(x = ss,decreasing = FALSE)