使用多层多边形构建的 ggplot 地图的手动图例

问题描述

我制作了以下地图,我对此很满意。但是,我无法为它成功制作一个传奇。在这种情况下,有什么办法可以制作手动图例吗?

我一直在尝试使用 scale_fill_manual,但这不起作用。我假设这是因为我已经从多个单独的多边形构建了图,因此没有一个数据集可以参考图例颜色。

如果有一种方法可以从单独的多边形制作图例,我很乐意听取您的建议! This question 看起来很相似,但解决方案涉及从世界地图创建一个国家子集的数据集,我一直无法思考如何为尚未成为一个内聚力的一部分的 m 个多边形执行此操作一组数据。

gabon <- ggplot() +
    geom_polygon(data = gabon0.fortified,aes(x = long,y = lat,group = group),#gabon background
                 fill="#E7D4E8",color=NA) +
    geom_polygon(data = permits.fortified,#logging permits
                 fill="#CCEEFF",color="#006191",size = 0.15,show.legend=TRUE) +
    geom_polygon(data = parks.fortified,#parks
                 fill="#CCDDAA",color="#4e6127",show.legend=TRUE) +
    geom_polygon(data = tc.subset.f,#seef
                 fill="#fef7ab",color="#5a5301",size = 0.3,show.legend=TRUE) +
    geom_polygon(data = one.fortified,show.legend=TRUE) +
    geom_polygon(data = before.fortified,show.legend=TRUE) +
    geom_polygon(data = gabon0.fortified,#gabon outline
                 fill=NA,color="black") +
    scale_fill_manual("Land area types",values = c("SEEF" = "#fef7ab","Logging permits" = "#CCEEFF","Protected areas" = "#CCDDAA","Gabon" = "#E7D4E8"),breaks = c("SEEF","Logging permits","Protected areas","Gabon")) +
    labs(title = "Gabon logging permit and protected areas",x = "latitude",y = "longitude",color = "Land areas") +
    theme_minimal() + theme

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)