I'm just wondering if it is possible to plot the regression line for a particular variable from a multivariate regression (using lm()
), while holding other variables at their mean, and fit the regression line on a bivariate scatter plot?
There's a function called cplot()
from margins
package that will do the trick but the function doesn't seem to be able to include data points on the X-Y plane. So I am wondering if someone has tried using lm()
function to do this?
library(ISLR)
data(Carseats)
lm.fit <- lm(Sales ~ Income + Advertising + Price, data = Carseats)
plot(Carseats$Income, Carseats$Sales, cex = 1.3, col = "red", pch = 19, main = "The relationship between Car Sales and Income", xlab = "Income", ylab = "Car Sales")
Is it possible to fit lm.fit
on the bivariate plot along the dimension of Sales
and Income
, while holding other variables at their means?