Skip to content

Instantly share code, notes, and snippets.

@adisarid
Created July 14, 2020 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adisarid/4687eae3bb52fb792a66df2146805868 to your computer and use it in GitHub Desktop.
Save adisarid/4687eae3bb52fb792a66df2146805868 to your computer and use it in GitHub Desktop.
Source of many frustrations when using fct_inorder
library(tidyverse)
example1 <- tibble(size = c("A", "A", "C", "C", "B", "B"),
re_order_var = c(1,1,2,2,3,3))
# works as expected:
example1 %>%
arrange(re_order_var) %>%
mutate(size = fct_inorder(size)) %>%
ggplot(aes(size, y = 1)) +
geom_col()
# But, this doesn't actually yield the desired outcome due to the grouping
example1 %>%
group_by(size) %>%
arrange(re_order_var) %>%
mutate(size = fct_inorder(size)) %>%
ggplot(aes(size, y = 1)) +
geom_col()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment