【问题标题】:points distribution in map with ggplot带有ggplot的地图中的点分布
【发布时间】:2020-07-11 06:29:23
【问题描述】:

我有这些文件和数据:

https://gofile.io/?c=JvglSo

https://pastebin.com/ePymwswn

还有这个脚本:

#open shp file
library(rgdal)
map <- readOGR(dsn= "/rj_municipios", layer = "33MUE250GC_SIR")

#open data file
ind_mapa <- read.csv("ind_mapa.csv", sep=";")

#map
library(ggplot2)
library(ggrepel)
mapdf <-fortify(map)

ggplot(data= mapdf, aes(x=long, y=lat, group=group)) +
  geom_path() +
  coord_map("mercator") +
  xlim(-42.040,-41.973)+
  ylim(-23.015, -22.949)+
  theme_bw() +
  geom_jitter(data=ind_mapa, width= .0015, height = .0015, size=3,alpha=.7,
              aes(x=lon, y=lat, group= code, color = code)) +
  geom_text_repel(data= ind_mapa, aes(x=lon, y=lat), group= code, label=ano)

我有两个问题,标签“ano”没有出现:

层错误(数据 = 数据,映射 = 映射,stat = stat,geom = GeomTextRepel,:找不到对象“代码”

我使用 geom_jitter 使点不会重叠,但它们会变得混乱,而不是均匀分布在原始点和中心点上。

【问题讨论】:

  • 您可能在geom_jittergeom_text_repel 中都需要inherit.aes = FALSE
  • 我刚试了一下,还是一样

标签: r dictionary ggplot2 point rgdal


【解决方案1】:

您的labelgroup 值需要符合审美标准。您的最后一行代码应为:

geom_text_repel(data= ind_mapa, aes(x=lon, y=lat, group= code, label=ano))

收到的错误信息给你一个提示:geom = GeomTextRepel, : object 'code' not found。使用它,您知道这是 geom_text_repel() 调用的问题,特别是 code 的参数。

有趣的事实:将最后一行更改为geom_text_repel(data= ind_mapa, aes(x=lon, y=lat, group= code), label=ano),其中只有group=codeaes() 调用中。您应该会看到相同的错误消息,但带有 object 'ano' not found

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-02
    • 2015-01-04
    • 1970-01-01
    • 1970-01-01
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多