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

如何避免spData::world国家跨地图边缘折回并裁剪地图绘图区域

问题根源

  • 你当前使用的WGS84(EPSG:4326)坐标系下,经度范围为[-180,180],俄罗斯远东、大洋洲部分岛屿跨180度经线,几何要素被分割在180度两侧,直接裁剪会出现要素丢失
  • 你写的st_crop参数ymin=-180、ymax=180存在错误,纬度合法范围仅为[-90,90],参数错误也会导致裁剪结果异常

解决方案

方法1:调整为太平洋中心投影,避免跨180截断

不需要裁剪,直接通过投影把展示中心移到东经150°附近,自然消除美洲区域的空白,跨180度的要素也会连续展示:

library(sf)
library(ggplot2)
library(spData)
library(dplyr)

# 过滤目标大洲
map = spData::world %>%
  filter(!continent %in% c("South America", "North America", "Antarctica"))

# 定义太平洋中心投影,中心经度设为150°E,适配欧亚非大洋的展示范围
pacific_proj <- "+proj=longlat +lon_wrap=150 +datum=WGS84 +no_defs"

# 转换坐标系
map_proj <- st_transform(map, crs = pacific_proj)

# 绘图
ggplot() + 
  geom_sf(data = map_proj, aes(geometry = geom)) +
  # 可选:手动限制坐标范围去掉多余空白
  coord_sf(xlim = c(-30, 210), ylim = c(-50, 80))

方法2:调整经度范围后正确裁剪

如果需要保留原始WGS84投影,先调整经度区间再执行裁剪:

library(sf)
library(ggplot2)
library(spData)
library(dplyr)

map = spData::world %>%
  filter(!continent %in% c("South America", "North America", "Antarctica")) %>%
  # 调整经度格式,把跨180度的要素合并到连续的0-360经度区间
  st_shift_longitude()

# 传入合法坐标范围裁剪
map_crop <- st_crop(map, xmin = -30, xmax = 210, ymin = -50, ymax = 80)

# 绘图
ggplot() + 
  geom_sf(data = map_crop, aes(geometry = geom))

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.14 00:09:00