Add a legend to a ggplot2 scatter plot including additional lines

旧城冷巷雨未停 提交于 2019-12-02 04:11:34
tonytonov

There is probably a simpler solution, but here's the best I could come up with so far.

ggplot(DF, aes(data1,data2)) + 
  geom_point(colour="dodgerblue",alpha=0.75) +
  geom_abline(aes(colour="abline", intercept=0, slope=1), linetype="dashed", alpha=1, size=1) +
  geom_smooth(aes(colour="lm_smooth"), method = "lm", se=FALSE) + 
  scale_colour_manual(name="lines", values=c("red", "blue")) + 
  guides(colour = guide_legend(override.aes = list(alpha = 0)))

Credit also goes here.

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