How to show abline of geom_abline in legend

余生颓废 提交于 2019-11-29 16:14:07
tkmckenzie

You can use the show_guide=TRUE argument:

plot1<- ggplot(df, aes(x)) +
  geom_line(size=0.5,lty="dashed", aes(y=y),color="Blue") +
  geom_abline(aes(slope=-0.62,intercept=1670,colour="break"), size=0.9,show_guide = TRUE)+
  geom_point(aes(y=y,shape="y"),size=4, color="Gray24",fill="Green")

You'll probably need to change the labels in the legend, but you should be able to do that with theme.

Edit: To remove the slash from the legend, you can use guides and override.aes:

plot1 <- ggplot(df, aes(x, y)) +
  geom_point(aes(shape = "y"), size = 4, color = "Gray24", lty = 0) +
  geom_line(size = 0.5, lty = "dashed", color = "Blue") +
  geom_abline(aes(slope = -0.62, intercept = 1670, colour = "break"), size = 0.9, 
               show_guide = TRUE) +
  guides(shape = guide_legend(override.aes = list(linetype = 0)))
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!