How to add a regression line to a ggplot?
library(ggplot2)
data(mtcars)
Step 1
p <- ggplot(mtcars, aes(hp, wt)) +
geom_point()
p
Step 2
p + geom_smooth()
Step 3
p + geom_smooth(method = "lm")
Putting it all together
ggplot(mtcars, aes(hp, wt)) +
geom_point() +
geom_smooth(method = "lm")