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

R语言中是否存在-360°至360°范围的世界国家多边形数据?

不需要额外寻找覆盖更大经度范围的多边形数据,仅需对现有数据做经度偏移处理即可实现跨本初子午线的自定义经度范围地图绘制。你给出的代码无法得到正确效果,是因为原有两类数据的经度范围边界和你需要的显示范围不匹配,直接设置xlim会导致多边形被截断、出现异常拉伸色块。

下面给出两种可用实现方案:

方案1:基于ggplot2自带map_data快速调整

library(ggplot2)
library(dplyr)

map_raw <- map_data('world')
# 偏移经度:将小于100°E的经度统一加360,使整体经度范围落在100°~460°区间
map_adjusted <- map_raw %>%
  mutate(long = if_else(long < 100, long + 360, long)) %>%
  # 过滤跨偏移边界的异常多边形,避免出现横穿地图的色块
  group_by(group) %>%
  filter(max(long) - min(long) < 180) %>%
  ungroup()

# 绘图
ggplot() +
  theme_bw() +
  geom_polygon(data = map_adjusted,
               aes(x = long, y = lat, group = group),
               fill = "white", col = "gray") +
  coord_fixed(1.4, xlim = c(100, 380))

方案2:基于sf空间数据的更稳定实现(推荐)

如果需要避免多边形截断、边界异常的问题,可使用rnaturalearth包提供的矢量地图数据结合sf的投影转换实现:

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

# 加载中精度世界国家矢量数据
world_sf <- ne_countries(scale = "medium", returnclass = "sf")
# 定义自定义中心的经纬度投影,将经度原点偏移至240°,匹配100°E~20°E的显示需求
target_crs <- st_crs("+proj=longlat +lon_wrap=240")
# 转换数据投影
world_sf_adj <- st_transform(world_sf, crs = target_crs)

# 绘图
ggplot() +
  theme_bw() +
  geom_sf(data = world_sf_adj, fill = "white", col = "gray") +
  coord_sf(xlim = c(100, 380), expand = FALSE)

两种方案都可以正确输出100°E到20°E跨本初子午线的世界地图,其中方案2支持多精度的地图数据选择,边界处理更稳定,适合科研绘图使用。

内容的提问来源于stack exchange,提问作者Santiago I. Hurtado

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.07 19:24:00