You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R绘制英格兰区域整洁地图空白,如何用rgdal转换英国坐标系?

解决英格兰区域地图ggplot空白问题:坐标系转换方案

问题根源

你加载的英格兰区域shapefile使用的是英国国家格网坐标系(OSGB36,EPSG:27700),即Eastings/Northings格式的平面坐标,而coord_map()默认适配WGS84(EPSG:4326)经纬度坐标系,两者不匹配导致绘图空白。

用rgdal转换坐标系的步骤

1. 确认原数据坐标系

先查看原始空间数据的投影信息,验证坐标系类型:

proj4string(eng_reg_map)

输出会包含+init=epsg:27700,对应OSGB36坐标系。

2. 转换为WGS84坐标系

使用spTransform()函数将空间数据转换为ggplot兼容的WGS84经纬度坐标系:

# 定义目标坐标系:WGS84(EPSG:4326)
wgs84 <- CRS("+init=epsg:4326")
# 执行坐标系转换
eng_reg_map_wgs84 <- spTransform(eng_reg_map, wgs84)

3. 重新生成tidy数据并绘图

基于转换后的空间数据生成tidy对象,再执行绘图代码:

# 生成适配WGS84的tidy格式数据
tidy_eng_reg_map <- tidy(eng_reg_map_wgs84, region = "rgn15nm")

# 绘制正常显示的地图
ggplot() +
  geom_polygon(data = tidy_eng_reg_map, aes(x = long, y = lat, group = group), fill = "white", colour = "black") +
  theme_void() +
  coord_map()

完整修正代码

library(tidyverse)
library(broom)
library(rgdal)

# 加载并检查原始地图
eng_reg_map <- readOGR(
  dsn = "./Region_(December_2015)_Boundaries"
)

plot(eng_reg_map) # 传统绘图可正常显示

# 转换坐标系为WGS84(EPSG:4326)
wgs84 <- CRS("+init=epsg:4326")
eng_reg_map_wgs84 <- spTransform(eng_reg_map, wgs84)

# 生成tidy格式数据
tidy_eng_reg_map <- tidy(eng_reg_map_wgs84, region = "rgn15nm")

# 绘制地图(现在可正常显示)
ggplot() +
  geom_polygon(data = tidy_eng_reg_map, aes(x = long, y = lat, group = group), fill = "white", colour = "black") +
  theme_void() +
  coord_map()

内容的提问来源于stack exchange,提问作者Tom Wagstaff

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 22:40:44