Different legend-keys inside same legend in ggplot2

You can use override.aes= inside guides() function to change default appearance of legend. In this case your guide is color= and then you should set shape=c(NA,16) to remove shape for line and then linetype=c(1,0) to remove line from point.

ggplot(df) +
  geom_line(aes(id, line, colour = "line")) +
  geom_point(aes(id, points, colour = "points"))+
  guides(color=guide_legend(override.aes=list(shape=c(NA,16),linetype=c(1,0))))

enter image description here

Leave a Comment