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

在R中用ggplot2绘制EPSG:3995北极极射投影北半球地图遇问题

解决R中ggplot2绘制北极极射投影(EPSG:3995)地图的问题

问题根源

  • 直接转换完整世界地图到北极极射投影时,南半球区域会被严重拉伸,导致ggplot自动调整的坐标范围偏离北极区域,显示异常。
  • 未裁剪到北纬20度以北的目标范围,多余区域干扰了地图的正常渲染。

解决方案代码

library(rnaturalearth)
library(ggplot2)
library(sf)

# 获取中等精度世界地图数据
worldmap <- ne_countries(scale = 'medium', returnclass = 'sf')

# 创建北纬20度以北的裁剪边界
north_20_bounds <- st_bbox(
  c(xmin = -180, xmax = 180, ymin = 20, ymax = 90), 
  crs = st_crs(4326) # WGS84坐标系
) %>% st_as_sfc()

# 裁剪地图到目标区域
worldmap_north <- st_intersection(worldmap, north_20_bounds)

# 转换为北极极射投影(EPSG:3995)
worldmap_trans <- st_transform(worldmap_north, st_crs(3995))

# 绘制地图并设置坐标范围聚焦北极
ggplot() +
  geom_sf(data = worldmap_trans) +
  coord_sf(xlim = c(-5e6, 5e6), ylim = c(-5e6, 5e6)) + # 适配北极区域的坐标范围
  theme_minimal()

关键步骤说明

  • 裁剪地图:通过st_bbox定义北纬20度的边界,再用st_intersection保留目标区域,剔除无关的低纬度和南半球部分,避免投影扭曲。
  • 投影转换:仅对裁剪后的区域进行投影转换,减少计算负载,同时避免异常区域干扰显示。
  • 坐标范围设置:使用coord_sf手动指定x/y轴范围,确保北极区域居中显示,解决ggplot自动缩放导致的显示偏移问题。

内容的提问来源于stack exchange,提问作者Evans Liu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 01:37:10