sf对象的尺寸图例无法显示正确的符号。

6

有人知道为什么size美学的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()

enter image description here


没有示例数据意味着很少有人能够使用您的示例代码。已经存在一个相关且已知的问题,该问题于2017年11月1日关闭。您尝试更新ggplot2了吗? - Maurits Evers
4
这个例子有示例数据。谢谢,我会尝试更新它。 - Tdebeus
对我来说,使用sf:0.6.1和ggplot2:2.2.1.9000也是一样的(这个版本比错误报告中提到的还要旧...) - Spacedman
1
仍然无法通过devtools使用github版本。仅使用size美学,您会得到错误的图例对象。 ggplot(nc_centers,aes(size = BIR74))+ geom_sf()解决方案?改用tmap - Spacedman
2
你说得对,我可以确认这个问题。我建议在相应的 sfggplot2 GitHub 问题下留言。 - Maurits Evers
这是一个重复的问题:https://dev59.com/fafja4cB1Zd3GeqP1M78?rq=1 - sebdalgarno
1个回答

12

您需要向geom_sf添加show.legend参数,例如:

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

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接