jhudsl/intro_to_r

`desc` inside `fct_reorder()`

Closed this issue · 2 comments

In the lecture , I said you could use desc() around the column inside fct_reorder() like this:

dropouts_fct %>% 
  ggplot(mapping = aes(
    x = fct_reorder(grade, desc(n_dropouts), max), 
    y = n_dropouts
  )) +
  geom_boxplot() +
  labs(x = "Grade")

It runs okay, but the output was not as expected! You should use the .desc argument inside fct_reorder() instead:

dropouts_fct %>% 
  ggplot(mapping = aes(
    x = fct_reorder(grade, n_dropouts, max, .desc = TRUE), 
    y = n_dropouts
  )) +
  geom_boxplot() +
  labs(x = "Grade")

Also re: fct_reorder... Could use an example that looks similar to this:

highcounts_females <- highcounts_females %>%
  mutate(
    Child_First_Name = as_factor(Child_First_Name),
    Child_First_Name = fct_reorder(Child_First_Name, -Count)
  )

Is the object highcounts_females something that is in this project somewhere? I did a search for it and can't find it in the modules. So for the example above I'm not sure where you'd like that to be added.