Skip to content

Instantly share code, notes, and snippets.

@timcdlucas
Created November 26, 2019 11:00
Show Gist options
  • Save timcdlucas/341ff9ce04af930af30acbd6612bd4de to your computer and use it in GitHub Desktop.
Save timcdlucas/341ff9ce04af930af30acbd6612bd4de to your computer and use it in GitHub Desktop.
Use fct_reorder in facet_wrap
library(forcats)
library(ggplot2)
ggplot(mtcars, aes(x = disp, y = mpg)) +
geom_point() +
facet_wrap(~ factor(gear))
ggplot(mtcars, aes(x = disp, y = mpg)) +
geom_point() +
facet_wrap(~ fct_reorder(factor(gear), disp))
ggplot(mtcars, aes(x = disp, y = mpg)) +
geom_point() +
facet_wrap(~ fct_reorder(factor(gear), disp, .fun = length))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment