[英]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.