我正在尝试将ESRI shapefile(.shp)添加到北卡罗来纳州的ggmap图中,其中包含以下代码:
x <- get_map(location="North Carolina", zoom=6, maptype="terrain")
ggmap(x) +
geom_polygon(data=citylim83.df, aes(x=long, y=lat), fill="red", alpha=0.2)
我加载并强化的shapefile citylim83.df
.以下是用于将shapefile加载到ggplot的代码:
epsgs <- make_EPSG()
citylim <- readOGR(dsn=".", layer="MunicipalBoundaries_polys")`
Run Code Online (Sandbox Code Playgroud)
在对EPSG进行搜索之后,MunicipalBoundaries投影的单位是国家 - 平面系统的ft-US.即使这个.shp的地理坐标系为NAD83,我也想把它投射到NAD83以摆脱状态平面系统(NAD83的EPSG代码(UTM-17N)是26917):
citylim83 <- spTransform(citylim, CRS("+init=epsg:26917"))
summary(citylim83)
Object of class SpatialPolygonsDataFrame
Is projected: TRUE
[+init=epsg:26917 +proj=utm +zone=17 +ellps=GRS80 +datum=NAD83 +units=m
citylim83.df <- fortify(citylim83)
Run Code Online (Sandbox Code Playgroud)
然后在上面显示的ggmap代码中使用该数据帧.
即使它现在已经被投射到NAD83中,它仍然不会出现在基础ggmap上.我导入的get_map对象的基本投影是什么?是否有命令找到这个,所以我可以将我的地图与我想要显示在其上的shapefile匹配?我是否必须"取消"我的citylim对象?仅供参考,如果不清楚,shapefile是北卡罗来纳州每个城市的城市限制边界.任何帮助都会非常感激,因为我对ggplot2/ggmap社区很新.