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

Exercise

Adding a linear smoother

You've seen how to add LOESS smoothers to a scatterplot by using both the add_markers() and add_lines() traces. Adding a linear smoother uses the same approach, but you use lm() command to fit the linear model.

In this exercise, your task is to add a linear smoother to a scatterplot of user score against critic score for video games in 2016.

When you add smoothers, missing values (NAs) can be problematic because many modeling functions automatically delete missing observations. To avoid this conflict, use select() and na.omit() to delete observations before plotting.

Note that plotly and the vgsales2016 data has already been loaded for you.

Instructions

100 XP
  • Fit a linear regression model using Critic_Score as the predictor variable and User_Score as the response variable. Store this model in the object m.
  • Create a scatterplot showing Critic_Score on the x-axis and User_Score on the y-axis.
  • Add a linear smoother to your scatterplot representing the fitted values.