【问题标题】:Size legend of sf object won't show correct symbolssf 对象的大小图例不会显示正确的符号
【发布时间】:2018-03-29 12:10:44
【问题描述】:

有谁知道为什么size aestatic BIR74 的图例不会显示点大小而是矩形?如果答案是肯定的,我该如何解决这个问题?

可重现的例子:

library(sf)
# devtools::install_github("tidyverse/ggplot2")
library(ggplot2)

nc <- st_read(system.file("shape/nc.shp", package="sf"))

nc_centers <- st_centroid(nc)

nc_centers %>%
  ggplot() +
  geom_sf(aes(color = SID79, size = BIR74)) +
  coord_sf(datum = NA) +
  theme_minimal()

【问题讨论】:

  • 没有示例数据意味着很少有人能够使用您的示例代码。存在于 2017 年 11 月 1 日关闭的 related and known issue。您是否尝试过更新 ggplot2
  • 示例有样本数据。谢谢,我会尝试更新它。
  • 对 sf:0.6.1 和 ggplot2:2.2.1.9000 (这比错误报告更早......)对我做同样的事情
  • 通过 devtools 的 github 版本仍然失败。仅使用size 美学,您就会得到错误的图例对象。 ggplot(nc_centers, aes(size=BIR74)) + geom_sf() 解决方案?改用tmap
  • 您在所有帐户上都是对的;我可以确认问题。我建议在各自的 sfggplot2 GitHub 问题上发表评论。

标签: r ggplot2 gis geospatial sf


【解决方案1】:

您需要将 show.legend 参数添加到 geom_sf,即

nc_centers %>%
  ggplot() +
  geom_sf(aes(color = SID79, size = BIR74), show.legend = 'point') +
  coord_sf(datum = NA) +
  theme_minimal()

【讨论】:

    猜你喜欢
    • 2020-05-05
    • 2020-06-23
    • 1970-01-01
    • 1970-01-01
    • 2020-06-20
    • 2022-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多