@lbusett
Hi thanks for the reply.
so is this the only way of using a model directly into ggplot2.
# read dataset
df = mtcars
# create multiple linear model
lm_fit <- lm(mpg ~ cyl + hp, data=df)
summary(lm_fit)
# save predictions of the model in the new data frame
# together with variable you want to plot against
predicted_df <- data.frame(mpg_pred = predict(lm_fit, df), hp=df$hp)
# this is the predicted line of multiple linear regression
ggplot(data = df, aes(x = mpg, y = hp)) +
geom_point(color='blue') +
geom_line(color='red',data = predicted_df, aes(x=mpg_pred, y=hp))
I am not looking for the the geom_smooth option. I was thinking may be there is something to geom_abline that I don't know yet.
Please let me know if that's the optimal solution.