[英]Overlaying ggmap , geom_polygon(shape file) on ggplot2
我有一个形状文件,我想用ggplot将其发布到Google地图的顶部,但是通过geom_polygon(ggplot2)发布会显示没有意义的行
我的代码:
######## the shape file ftp://geoftp.ibge.gov.br/organizacao_do_territorio/malhas_territoriais/malhas_municipais/municipio_2015/Brasil/BR/
download.file("ftp://geoftp.ibge.gov.br/organizacao_do_territorio/malhas_territoriais/malhas_municipais/municipio_2015/Brasil/BR/br_municipios.zip",temp)
data <- unz(temp, "BRMUE250GC_SIR.shp")
data.shape<-st_read(data)
####### the map from ggmap
mapa_edital_guarulhos <- get_map(location="GUARULHOS-SP",zoom=11,color = "bw",
maptype = "roadmap")
mapa_edital_guarulhos_01<- ggmap(mapa_edital_guarulhos)
########## plotting with ggplot
mapa_edital_guarulhos1 <- mapa_edital_guarulhos_01 +
geom_polygon(aes(x=long,y=lat, group=group), data=shape.sp,
color='black',alpha=0)
结果:
箭头显示了在我的图中没有意义的线,仅绘制了相同间隔的形状:
plot(shape.sp,xlim=c(-47.25,-46.95),ylim=c(-23.1,-22.7))
我的代码有什么问题? 谢谢
尝试使用geom_sf而不是geom_polygon
首次安装ggplot2的开发版本
devtools::install_github('tidyverse/ggplot2')
# read using sf instead of readOGR
library(sf)
# something like:
data.shape <- st_read("www./BRMUE250GC_SIR.shp")
####### the map from ggmap
mapa_edital_guarulhos <- get_map(location="GUARULHOS-SP",zoom=11,color = "bw",
maptype = "roadmap")
mapa_edital_guarulhos_01<- ggmap(mapa_edital_guarulhos)
########## plotting with ggplot
mapa_edital_guarulhos1 <- mapa_edital_guarulhos_01 +
geom_sf(data = data.shape, color = 'black', alpha=0)
没有数据集很难测试。 但是,让我知道是否可行! 我已经看到这可以解决您之前遇到的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.