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:
plot(log.SVL.final~log.Age.DPO, data=RxP.byTank)abline(3.44001,-0.11624)
A shortcut for when we have a simple linear regression—that is,when we only have a single continuous predictor—is to just put the name of the model object in parentheses. For example, we could use abline(lm4)
. The function knows to get the intercept and regression from the model. This doesn’t work with models that have multiple predictors.
To plot the regression back on the original data, we have to do some work ourselves. This is a great way to explore how to interpret a linear regression. Recall that the equation for the ...