Scatterplots in ggplot2
Scatter plots with multiple groups
Add regression lines
Regression lines can be added as follow:
# Add regression lines ggplot(mtcars, aes(x=wt, y=mpg, color=cyl, shape=cyl)) + geom_point() + geom_smooth(method=lm) # Remove confidence intervals # Extend the regression lines ggplot(mtcars, aes(x=wt, y=mpg, color=cyl, shape=cyl)) + geom_point() + geom_smooth(method=lm, se=FALSE, fullrange=TRUE)
Note that you can also change the line type of the regression lines by using the aesthetic linetype = cyl.
The fill color of confidence bands can be changed as follow :
ggplot(mtcars, aes(x=wt, y=mpg, color=cyl, shape=cyl)) + geom_point() + geom_smooth(method=lm, aes(fill=cyl))