CommencerCommencer gratuitement

Which state had the highest turnout?

The hover information on the previous scatterplot allows you to determine which state had the highest turnout, but it takes considerable time to compare the turnout between states. In this exercise, your task is to create a scatterplot displaying state on the y-axis and voter turnout on the x-axis. Scatterplots displaying one categorical and one quantitative variable are often called dotplots, and allow for quicker comparisons between groups.

The turnout dataset contains information on the proportion of eligible voters (turnout) that voted in the 2018 midterm election in each state.

In the sample code, turnout %>% slice_max(turnout2018, n = 15) extracts the 15 states with the highest turnout rates.

Note that plotly, dplyr, and forcats have already been loaded for you.

Cet exercice fait partie du cours

Interactive Data Visualization with plotly in R

Afficher le cours

Instructions

  • For the top 15 states, create a dotplot (i.e. scatterplot) displaying turnout2018 on the x-axis and state on the y-axis, where state has been reordered by turnout2018.
  • Title the x-axis "Eligible voter turnout".
  • Title the y-axis "State" and set its type to category.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Create a dotplot of voter turnout in 2018 by state ordered by turnout
turnout %>%
  slice_max(turnout2018, n = 15) %>%
  ___(x = ___, y = ~fct_reorder(___, ___)) %>%
  ___() %>%
  layout(___, 
         ___)
Modifier et exécuter le code