This code plots regression lines with interactions in ggplot2:
library(ggplot2)
ggplot(mtcars, aes(hp, mpg, group = cyl)) + geom_point() + stat_smooth(method = "lm")
Can lines without interactions be plotted with stat_smooth
?
This code plots regression lines with interactions in ggplot2:
library(ggplot2)
ggplot(mtcars, aes(hp, mpg, group = cyl)) + geom_point() + stat_smooth(method = "lm")
Can lines without interactions be plotted with stat_smooth
?
Workaround would be to make model outside the
ggplot()
. Then make predicition for this model and add result to the original data frame. This will add columnsfit
,lwr
andupr
.Now you can use
geom_line()
withfit
values asy
to add three regression lines andgeom_ribbon()
withlwr
andupr
to add confidence interval.