我使用R在世界地图上使用ggplot2的大圆圈投影一些数据流.我想也可以在我的地图上预测城市地区:http: //www.naturalearthdata.com/downloads/
但是,它们位于SpatialPointsDataFrame中.也许我的问题很简单,但我不知道如何将文件更改为SpatialPolygons.
我的代码如下:
urbanareasin <- readShapePoly("//....//ne_10m_populated_places//ne_10m_populated_places.shp")
simp<-gSimplify(urbanareasin, tol=0.1)
urbanareas<-ggplot2:::fortify(simp)
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
urbanareas<-fortify.SpatialPolygonsDataFrame(simp)
Run Code Online (Sandbox Code Playgroud)
和:
urbanareas<-ggplot2:::fortify.SpatialPolygonsDataFrame(simp)
Run Code Online (Sandbox Code Playgroud)
但它们都不起作用.我不得不遗漏一些东西......我是R的初学者,我会很感激任何建议.
先感谢您!
PS.查找以下数据信息:
str(urbanareasin) # to get info about the object
Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
..@ data :'data.frame': 7322 obs. of 92 variables:
.. ..$ SCALERANK : int [1:7322] 10 10 10 10 10 10 10 10 10 10 ...
.. ..$ NATSCALE : int [1:7322] 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ LABELRANK …Run Code Online (Sandbox Code Playgroud)