0

I'm trying to show both the geom_line and the geom_point in the legend, however I can't seem to get the geom_line to appear.

graph <- ggplot(mar, aes(x=long, y=lat)) +  xlab("Longitude") + ylab("Latitude") + labs(size = "Distance from predicted \n to known Roman road (m)")
graph  + theme_light() + geom_point(aes(size=distance$NEAR_DIST)) +  geom_line(color="white", size=0.5)

This generates a graph with geom_point (size of points are based on distance from the line in geom_line and another line), but I can't get the geom_line to appear in the legend. Any ideas on how to do this?

enter image description here

user3384265
  • 173
  • 11
  • Only properties that are mapped via aesthetics are placed in a legend. What exactly do you want this legend to day? – MrFlick Jul 18 '17 at 18:23
  • Possible duplicate: https://stackoverflow.com/questions/39328023/adding-legend-to-a-single-line-chart-using-ggplot – MrFlick Jul 18 '17 at 18:25
  • Possible duplicate: https://stackoverflow.com/questions/24496984/how-to-add-legend-to-ggplot-manually-r – MrFlick Jul 18 '17 at 18:25
  • Thanks for the reply. I did check similar questions, but I couldn't find anything. I'm trying to get the "geom_line" (white line) to appear in the legend, showing the line with a heading saying "LCP Roman road" – user3384265 Jul 18 '17 at 18:27
  • As stated earlier, you need to assign `color` via an aesthetic. Something like `geom_line(aes(color = "LCP Roman Road"), size = 0.5) + scale_color_manual(name = "", values = "white")` – MeetMrMet Jul 18 '17 at 18:30
  • That works perfectly! Thank you. – user3384265 Jul 18 '17 at 18:33

1 Answers1

0

Answered by Craig:

graph <- ggplot(mar, aes(x=long, y=lat)) + xlab("Longitude") + ylab("Latitude") + labs(size = "Distance from predicted \n to known Roman road (m)")

graph  + theme_dark() + geom_point(aes(size=distance$NEAR_DIST)) +  geom_line(aes(color = "LCP Roman Road"), size = 0.5) + scale_color_manual(name = "tt", values = "white")

assigned color via an aesthetic.

user3384265
  • 173
  • 11