参考自《R数据可视化手册》
拟合回归线往往在科研论文等研究变量之间关系时常用到:
library(ggplot2)
library(gcookbook)
#生成一个半成品,备用
hw_sp <- ggplot(heightweight, aes(x = ageYear, y = heightIn))
一、添加线性拟合回归线,并默认添加95%的置信区间
hw_sp +
geom_point() +
stat_smooth(method = lm)
二、添加线性拟合回归线,并手动添加99%的置信区间
hw_sp +
geom_point() +
stat_smooth(method = lm, level = 0.99)
三、添加线性拟合回归线,但不添加置信区间
hw_sp +
geom_