Add multiple legends to ggplot2 when using geom_sf

て烟熏妆下的殇ゞ 提交于 2019-12-06 15:54:17

I'm not certain that I understand exactly what you want. Here we map values "A" and "B" to the color aestetic in order to obtain a legend and then we customize the colors with scale_color_manual

dataset1 <- st_sf(st_sfc(list(line1)))
dataset2 <- st_sf(st_sfc(list(line2)))

ggplot() + 
    geom_sf(data= dataset1, aes(color="A"), show.legend = "line") +
    geom_sf(data= dataset2, aes(color="B"), show.legend = "line") +
    scale_color_manual(values = c("A" = "red", "B" = "blue"), 
                       labels = c("Line1", "Line2"),
                       name = "Which line ?") 

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