向散点图中添加回归线
ggplot(data=, aes(x=, y=))+geom_smooth(method=, formula=, level=, se=, color=, fill=, alpha=)+geom_point(color=, size, alpha=)
method: 进行回归的方式
formula=: 进行回归的公式,例如:y ~ x+1,y ~ log(x)等
level=: 绘制的置信区间,默认为0.95
se=: 逻辑值,是否绘制置信区间,默认为TRUE
alpha=: 绘制点的透明度,0为完全透明,1为完全不透明
color=:geom_smooth()中代表回归线的颜色
fill=:geom_smooth()中代表置信区间的颜色
alpha=:geom_smooth()中代表置信区间的透明度
N = 300
x <- 1:N+rnorm(N, 10, 60)
y <- 1:N+rnorm(N, 10, 60)
type=sample(c('type_1','type_2'), N, replace=TRUE)
kk = data.frame(x=x, y=y, type=type)
ggplot(data = df, aes(x=x, y=y))+geom_smooth(method='lm', level=0.99)+geom_point(color=colour, size=2, alpha=0.5)+theme_cowplot() '#示例一
ggplot(data = df, aes(x=x, y=y))+geom_smooth(method='gam',level=0.99)+geom_point(color=colour, size=2, alpha=0.5)+theme_cowplot() #示例二
示例一
示例二














网友评论