1. Learn
  2. /
  3. Courses
  4. /
  5. Interactive Data Visualization with plotly in R

Exercise

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.

Instructions

100 XP
  • 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.