Regression line for the entire dataset together with regression lines based on groups in R ggplot2 ?

走远了吗. 提交于 2019-11-29 07:54:30

Try placing the colour, shape, linetype aesthetics not in the original call to ggplot2

You can then add the overall line with a different colour

set.seed(1)
library(plyr)
alldata <- ddply(data.frame(group = letters[1:5], x = rnorm(50)), 'group', 
                 mutate, y=runif(1,-1,1) * x +rnorm(10))



ggplot(alldata,aes(y = y, x = x)) +
     geom_point(aes(colour= group, shape= group), size = 3, alpha = .8) + 
     geom_smooth(method="lm", se= F, size = 1, aes(linetype = group, group = group)) +
     geom_smooth(method = 'lm',size = 1, colour = 'black', se = F) + theme_bw()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!