使用R中的GADM数据绘制英国区域

问题描述

我想制作一张英国地图,并能够按颜色对区域进行颜色编码。我的数据集中包含的区域包括东北,东南,西米德兰兹,威尔士,北爱尔兰等

我一直在使用gadm数据集,但这似乎没有此数据。它要么不够详细(按国家/地区划分),要么过于精细。我可以下载其他包含区域的数据集吗?目前,我只能制作地图

library(sp) 

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

解决方法

GADM数据集的详细信息取决于请求的详细信息级别。尝试使用getData包中的函数raster

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

我认为您要查找的区域可以在国家统计局的“行政边界”的“区域”类别下找到。它们仅包含英格兰境内的边界,因此必须分别下载不同的英国国家/地区概述,并且将这两个集合结合在一起。幸运的是,ONS具有GeoJSON API。

这里是完整的代表:

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()

reprex package(v0.3.0)于2020-09-06创建