[英]points distribution in map with ggplot
I have this files and data:我有这个文件和数据:
https://gofile.io/?c=JvglSo https://gofile.io/?c=JvglSo
https://pastebin.com/ePymwswn https://pastebin.com/ePymwswn
and this script:和这个脚本:
#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)
with this I have two problems, the label "ano" does not appear:对此我有两个问题,标签“ano”没有出现:
Error in layer(data = data, mapping = mapping, stat = stat, geom = GeomTextRepel, : object 'code' not found层错误(数据 = 数据,映射 = 映射,统计 = 统计,geom = GeomTextRepel,:未找到对象“代码”
and I used geom_jitter so that the dots don't overlap, but they get messy instead of being equally distributed over the original and central point.我使用 geom_jitter 使点不重叠,但它们变得凌乱而不是均匀分布在原始点和中心点上。
Your label
and group
values need to be in an aesthetic.您的label
和group
值需要符合审美。 Your last line of code should read:你的最后一行代码应该是:
geom_text_repel(data= ind_mapa, aes(x=lon, y=lat, group= code, label=ano))
The error message received gives you a hint: geom = GeomTextRepel, : object 'code' not found
.收到的错误消息给了你一个提示: geom = GeomTextRepel, : object 'code' not found
。 Using that, you know that it's a problem with the geom_text_repel()
call and specifically the argument for code
.使用它,您知道这是geom_text_repel()
调用的问题,特别是code
的参数。
Fun fact: change that last line to read geom_text_repel(data= ind_mapa, aes(x=lon, y=lat, group= code), label=ano)
, where only group=code
is in the aes()
call.有趣的事实:将最后一行更改为geom_text_repel(data= ind_mapa, aes(x=lon, y=lat, group= code), label=ano)
,其中只有group=code
在aes()
调用中。 You should expect to see the same error message, but with object 'ano' not found
.您应该会看到相同的错误消息,但object 'ano' not found
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.