Aan de slagGa gratis aan de slag

Adding a reference line

While it was not difficult to determine that higher proportions of eligible voters turned out in nearly every state from your last plot, it probably took you a little time to see this. Hover info certainly makes this task easier, but interactivity alone isn't enough to make this task "easy."

So how can you help readers digest your chart more quickly? By adding the reference line \(y=x\). Observations that fall above this reference line will correspond to states with higher voter turnout in 2018. In plotly, you can add a line by connecting two points using add_lines(x = c(x1, x2), y = (y1, y2)).

Your task is to add the \(y=x\) reference line to your previous plot.

Note that your plot from the last exercise is stored in the object p.

Deze oefening maakt deel uit van de cursus

Interactive Data Visualization with plotly in R

Cursus bekijken

Oefeninstructies

  • Use add_lines() to add a reference line passing through the points (0.25, 0.25) and (0.6, 0.6).
  • Hide the legend that's added to the chart by default.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Add the line y = x to the scatterplot
p %>%
  ___(x = c(___, ___), y = c(___, ___)) %>%
  ___
Code bewerken en uitvoeren