[英]Plot a tidy map of English regions
我正在尝试 plot 一个整洁的 map R 的英语地区。 我正在使用在其他 shapefile 上成功运行的代码,但是当我运行此代码时,代码执行时没有错误,但随后只显示一个空白图像。 我可以使用传统方法 plot 空白 map ,整洁的 object 在我看来很好,所以我不知道发生了什么。
这是我正在使用的代码:
library(tidyverse)
library(broom)
library(rgdal)
# load and check the English regions map
eng_reg_map <- readOGR(
dsn = "./Region_(December_2015)_Boundaries"
)
plot(eng_reg_map)
# make a tidy map
tidy_eng_reg_map <- tidy(eng_reg_map, region = "rgn15nm")
# blank map
ggplot() +
geom_polygon(data = tidy_eng_reg_map, aes(x = long, y = lat, group = group), fill = "white", colour = "black") +
theme_void() +
coord_map()
我正在使用的 shapefile 可在此处获得(您必须 select 列表中的 shapefile - 抱歉,我无法提供直接链接)。
有谁知道是什么问题?
(GIS Stack Exchange 上的交叉发布)
编辑一个朋友让我走到了一半:问题是纬度和经度是英国风格的东向和北向,而不是全球坐标。 有人知道使用rgdal
转换它们的方法吗?
有关使用sf
的选项,请参见下文。 这有两个原因:
rgdal
即将退休:请注意,rgdal 将于 2023 年底退役,计划尽早使用 GDAL 和 PROJ 过渡到 sf/stars/terra 功能。
实际上,我使用readOGR
(您的代码)运行时也会出错:
OGRSpatialRef 中的错误(dsn,层,morphFromESRI = morphFromESRI,dumpSRS = dumpSRS,:(从警告转换)Proj4 定义中丢弃的数据 Ordnance_Survey_of_Great_Britain_1936:+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs
broom::tidy()
已弃用:错误:(从警告转换)数据框整理器已弃用,并将在即将发布的 broom 中删除。
library(ggplot2)
library(sf)
eng_reg_map <-
st_read("./Region_(December_2015)_Boundaries/Region_(December_2015)_Boundaries.shp")
eng_reg_map |>
ggplot() +
geom_sf(fill = "white",
colour = "black") +
theme_void()
Output:
更新:
在这种情况下,导入也是整洁的,并允许加入:
library(dplyr)
library(ggplot2)
library(sf)
eng_reg_map |>
left_join(tibble(rgn15nm = c("North East",
"North West",
"Yorkshire and The Humber",
"East Midlands",
"West Midlands",
"East of England",
"London",
"South East",
"South West"),
pop = seq(1000, 9000, by = 1000))) |>
ggplot(aes(fill = pop)) +
geom_sf(colour = "black") +
theme_void()
Output:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.