Created
July 14, 2020 13:01
-
-
Save adisarid/4687eae3bb52fb792a66df2146805868 to your computer and use it in GitHub Desktop.
Source of many frustrations when using fct_inorder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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