Making better plots

Categorical Data in the Tidyverse

Emily Robinson

Data Scientist

A scatterplot with "problem" on the y-axis and "percentage considering a problem" on the x-axis. Problems include Expectations, Dirty Data, and Domain Expertise. The plot is not ordered so the points are scattered around.

Categorical Data in the Tidyverse

Reordering factors

ggplot(WorkChallenges, aes(x = fct_reorder(question, perc_problem),
                           y = perc_problem)) +
  geom_point() + 
  coord_flip()              

The same scatterplot as before but now ordered so from left to right it goes from the least percentage considering a problem to the most.

Categorical Data in the Tidyverse

A bar graph with job title on the y-axis and count on the x-axis. The bar is not ordered by count.

Categorical Data in the Tidyverse

Reordering bar chart

ggplot(multiple_choice_responses, aes(x = fct_infreq(CurrentJobTitleSelect)) +
   geom_bar() +
   coord_flip()              

The same bar chart as before but now ordered from top to bottom in increasing count.

Categorical Data in the Tidyverse

Reversing factor levels

ggplot(multiple_choice_responses, aes(x = fct_rev(fct_infreq(CurrentJobTitleSelect)))) +
    geom_bar() + 
    coord_flip()

The same bar chart as before but now ordered from top to bottom in decreasing count.

Categorical Data in the Tidyverse

Let's practice!

Categorical Data in the Tidyverse

Preparing Video For Download...