In the notes, why it is often suggested to use mutate() to reorder the factors first instead of directly applying them in ggplot() by setting the aes(fct_infreq())? @bensoltoff
e.g., why in the solution, the code
It isn't inherently better. I did it that way to distinguish the data transformation operations from the data visualization functions. But it will work either way.
In the notes, why it is often suggested to use mutate() to reorder the factors first instead of directly applying them in ggplot() by setting the aes(fct_infreq())? @bensoltoff e.g., why in the solution, the code
intent_levels <- c("Accidental", "Homicide", "Suicide", "Undetermined")
gun_deaths %>% drop_na(intent) %>% mutate(intent = parse_factor(intent, levels = intent_levels) %>% fct_infreq() %>% fct_rev()) %>% ggplot(mapping = aes(x = intent)) + geom_bar()
is better than
gun_deaths %>% ggplot(mapping = aes(intent %>% fct_infreq())) + geom_bar()
@bensoltoff