如何使用ggmap绘制带孔的shp?

问题描述 投票:3回答:1

我想在这里绘制一个* .shp文件ArcGis。看看我从中获取数据的page,我希望彩色区域看起来像这样:

the map how I would expect it to be

但是当我绘制它时,我会得到一些不同的东西(见下文)。特别是,似乎有些多边形重叠,有些区域填充了双层蓝色(alpha为.5),而它们应该是空的。

library(ggmap)
brMap <- qmap(location = 'baton rouge',  zoom = 10, maptype = 'terrain') 

library(rgdal)
indundationArea <- readOGR('dataset/Estimated_Flood_Inundation_Area/Estimated_Flood_Inundation_Area.shp')
ogrInfo('dataset/Estimated_Flood_Inundation_Area/Estimated_Flood_Inundation_Area.shp')
indundationArea <- spTransform(indundationArea, CRS("+proj=longlat +datum=WGS84"))
indundationArea <- fortify(indundationArea)

brMap +
  geom_polygon(aes(x=long, y=lat, group=group), size=.2,color='blue', fill = 'blue', alpha=.5, data=indundationArea)

enter image description here

r ggplot2 ggmap sp
1个回答
4
投票

您的问题是由带孔的多边形引起的。 geom_polygon目前无法正确绘制这些。因此,您应该像这样使用ggpolypath::geom_polypath

# continue after fortify
library(ggpolypath)
brMap +
  geom_polypath(data = indundationArea, 
               aes(x=long, y=lat, group=group), 
               size=.2,
               color='blue', 
               fill = 'blue', 
               alpha=.5) 

enter image description here

另一种选择可能是this one。但是,它对我不起作用......

© www.soinside.com 2019 - 2024. All rights reserved.