ggplot2: Different legend symbols for points and lines

情到浓时终转凉″ 提交于 2019-11-28 06:28:35

override.aes is definitely a good start for customizing the legend. In your case you may remove unwanted shape in the legend by setting them to NA, and set unwanted linetype to blank:

ggplot(data = NDVI2, aes(x = LAI2, y = NDVI, colour = Legend)) + 
  geom_point(size = 3) +
  geom_smooth(aes(group = 1, colour = "Trendline"),
               method = "loess", se = FALSE, linetype = "dashed") +
  geom_smooth(aes(group = 1, colour = "Regression (log)"),
               method = "lm", formula = y ~ log(x), se = FALSE, linetype = "solid") +
  scale_colour_manual(values = c("purple", "green", "blue", "yellow", "magenta","orange", "cyan", "red", "black"),
                       guide = guide_legend(override.aes = list(
                         linetype = c(rep("blank", 7), "solid", "dashed"),
                         shape = c(rep(16, 7), NA, NA))))

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