【发布时间】:2017-01-31 17:48:33
【问题描述】:
我无法让 ggplot 的 fortify 或 broom 的 tidy 包含区域,即使我按照另一篇文章中的建议加载了 maptools 库。
我首先加载了一堆库,包括 maptools (0.8-41)、rgeos (0.3-22)、broom (0.4.1) 和 ggplot2 (2.2.1.9000)。接下来,我使用以下命令抓取一张世界地图,其中包含一系列不同的区域选择,包括我感兴趣的一个 - ISO_a3。
world <- readOGR(dsn="https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/ne_50m_admin_0_countries.geojson", layer="OGRGeoJSON")
接下来我运行map <- broom::tidy(world, region = "iso_a3")
head(map) 生成以下内容。请注意,不包括任何地区列。
long lat order hole piece group id
1 48.93857 11.258447 1 FALSE 1 -99.1 -99
2 48.93848 10.982324 2 FALSE 1 -99.1 -99
3 48.93848 10.714209 3 FALSE 1 -99.1 -99
4 48.93838 10.433252 4 FALSE 1 -99.1 -99
5 48.93828 9.973486 5 FALSE 1 -99.1 -99
6 48.93828 9.807617 6 FALSE 1 -99.1 -99
【问题讨论】:
-
您的 github 链接(在 readOGR 中)已损坏。
-
文件可以在
https://github.com/nvkelso/natural-earth-vector/blob/master/geojson/ne_50m_admin_0_countries.geojson.gz下载,命令改为world <- readOGR(dsn = "xxx/ne_50m_admin_0_countries.geojson", layer = "OGRGeoJSON"),其中xxx是文件所在方向的路径。