简体   繁体   English

在 R 中使用 GADM 数据绘制英国地区

[英]Plotting UK regions using GADM data in R

I want to produce a map of the UK, and be able to colour code regions by colour.我想制作英国地图,并能够按颜色对区域进行颜色编码。 The regions I have in my dataset include North East, South East, West Midlands, Wales, Norther Ireland etc我的数据集中的地区包括东北、东南、西米德兰兹、威尔士、北爱尔兰等

I have been using the gadm dataset, but this doesn't seem to have this data.我一直在使用 gadm 数据集,但这似乎没有这个数据。 It is either not enough detail and by country, or is too granular.它要么不够详细且按国家/地区划分,要么过于细化。 Is there any other dataset which I could download which will have the regions?我可以下载其他包含区域的数据集吗? At the moment I have only got as far as producing the map目前我只能制作地图

library(sp) 

gadm <- readRDS("C:/Users/User/Documents/R_input/gadm36_GBR_2_sp.rds")
plot(gadm)

The details of GADM datasets depend on the level of details requested. GADM 数据集的详细信息取决于请求的详细信息级别。 Try the the function getData from raster package.尝试使用raster包中的getData函数。

library(raster)
# gadm <- <- getData('GADM', country='GBR', level=2) # the one you have
gadm <- getData('GADM', country='GBR', level=3) # more detailed than yours
plot(gadm)

I think the regions you are looking for can be found under the "Regions" category of "Administrative Boundaries" at the Office for National Statistics.我认为您正在寻找的地区可以在国家统计局的“行政边界”的“地区”类别下找到。 They only contain boundaries within England, so the different UK country outlines must be downloaded separately and the two sets joined together.它们只包含英格兰境内的边界,因此必须单独下载不同的英国国家大纲,并将这两个集合连接在一起。 Fortunately the ONS has a GeoJSON API.幸运的是,ONS 有一个 GeoJSON API。

Here's a full reprex:这是一个完整的reprex:

eng <- rgdal::readOGR(paste0("https://opendata.arcgis.com/datasets/",
                              "8d3a9e6e7bd445e2bdcc26cdf007eac7_4.geojson"))

countries <- rgdal::readOGR(paste0("https://opendata.arcgis.com/datasets/",
                                   "92ebeaf3caa8458ea467ec164baeefa4_0.geojson"))

eng <- sf::st_as_sf(eng)
countries <- sf::st_as_sf(countries)
UK <- countries[-1,] 
names(eng)[3] <- "Region"
names(UK)[3] <- "Region"
UK$objectid <- 10:12
eng <- eng[-2]
UK <- UK[c(1, 3, 9:11)]
UK <- rbind(eng, UK)

ggplot2::ggplot(UK, ggplot2::aes(fill = Region)) + ggplot2::geom_sf()

Created on 2020-09-06 by the reprex package (v0.3.0)reprex 包(v0.3.0) 于 2020 年 9 月 6 日创建

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM