Plotting the Regression

Learn how to plot the results of the regression.

The abline() function

The abline() function plots a straight line on an existing scatterplot. It requires two arguments: an intercept (a) and a slope (b). Thus, in R’s terminology, the equation for a straight line is y = a + bx. We can also pass other optional plotting parameters if we want to change the line width, style, color, and so on. Let’s draw a simple regression plot in base graphics as follows:

Get hands-on with 1200+ tech skills courses.