Session Ready
Exercise

Using lm() To Add A Regression Line To Your Plot

In the last exercise you used lm() to obtain the coefficients for your model's regression equation, in the format lm(y ~ x). takes the y variabWe can store this output and use it to add the regression line to your scatterplots! After you have created your scatterplot, you can add a line using the function abline(). abline() takes the intercept of the line as its first argument, and the slope of the line as its second argument. This makes it a pretty good candidate for storing your lm() output as an object, and putting it straight into abline. Let's try this out!

Instructions
100 XP
  • Use lm() to obtain the regression coefficients for your model. Assign this to an object called line
  • Use abline() to add a line to your graph based on the output of "line"