簡體   English   中英

ggplot地圖中的點分布

[英]points distribution in map with ggplot

我有這個文件和數據:

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”沒有出現:

層錯誤(數據 = 數據,映射 = 映射,統計 = 統計,geom = GeomTextRepel,:未找到對象“代碼”

我使用 geom_jitter 使點不重疊,但它們變得凌亂而不是均勻分布在原始點和中心點上。

您的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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM