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.
Diese Übung ist Teil des Kurses
Interactive Data Visualization with plotly in R
Anleitung zur Übung
- For the top 15 states, create a dotplot (i.e. scatterplot) displaying
turnout2018on the x-axis andstateon the y-axis, wherestatehas been reordered byturnout2018. - Title the x-axis
"Eligible voter turnout". - Title the y-axis
"State"and set itstypetocategory.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Create a dotplot of voter turnout in 2018 by state ordered by turnout
turnout %>%
slice_max(turnout2018, n = 15) %>%
___(x = ___, y = ~fct_reorder(___, ___)) %>%
___() %>%
layout(___,
___)