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

如何用R绘制南极洲120°E至60°W的西半部分地图

解决南极洲罗斯海区域(120°E至60°W)地图绘制问题

你遇到的核心问题是跨180°经线的区间筛选,直接用coord_map的xlim或scale_x_continuous的limits无法正确识别120°E到60°W这个非连续的经度范围(该范围包含120°E至180°,以及-180°至60°W两段)。下面是基于你现有代码修改的正确实现:

修正后的完整代码

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

# 1. 获取世界地图的sf格式数据,方便处理跨180°的区域
wm_sf <- ne_countries(scale = "medium", returnclass = "sf")

# 2. 筛选目标经度范围:120°E 至 60°W(即long >=120 或 long <=-60)
# 同时只保留南极洲(可选,若需要显示其他南部陆地可去掉这行)
wm_target <- wm_sf[wm_sf$continent == "Antarctica" & (wm_sf$longitude >= 120 | wm_sf$longitude <= -60), ]

# 定义经纬线标注所需的参数
x_lines <- c(120, 180, -120, -60)  # 目标范围内的关键经线
lat_labels <- seq(55, 85, by = 10)
lat_pos <- seq(-55, -85, by = -10)

# 绘制地图
ggplot() +
  # 绘制筛选后的陆地
  geom_sf(data = wm_target, fill = "grey", colour = "black", alpha = 0.8) +
  
  # 极地投影设置,orientation参数保持你的原设置
  coord_sf(crs = "+proj=ortho +lat_0=-90 +lon_0=210",
           xlim = c(120, -60),  # 这里的xlim现在能正确生效,因为数据已经筛选过
           ylim = c(-90, -60)) +
  
  # 调整坐标轴和标注
  scale_y_continuous(breaks = seq(-45, -90, by = -10), labels = NULL) +
  scale_x_continuous(breaks = x_lines, labels = c("120°E", "180°", "120°W", "60°W")) +
  labs(x = "", y = "") +
  
  # 添加纬度标注
  geom_text(aes(x = 90, y = lat_pos, hjust = -0.2, label = paste0(lat_labels, "°S"))) +
  
  # 添加经纬线
  geom_hline(yintercept = -60, size = 1) +
  geom_segment(aes(y = -60, yend = -90, x = x_lines, xend = x_lines), linetype = "dashed") +
  
  # 主题设置
  theme(panel.background = element_blank(),
        panel.grid.major = element_line(size = 0.25, linetype = 'dashed', colour = "black"),
        axis.ticks = element_blank(),
        axis.text.x = element_text(vjust = 1))

关键修改说明

  • 改用sf格式数据:ne_countries直接获取sf对象,比map_data更适合处理空间范围筛选,尤其是跨180°经线的情况。
  • 精准筛选目标区域:通过(longitude >=120 | longitude <=-60)选中120°E到60°W的所有区域,同时可选保留南极洲,避免显示无关陆地。
  • 使用coord_sf替代coord_map:coord_sf是ggplot2中处理sf数据的专用投影函数,配合crs参数设置极地正交投影,比coord_map更稳定,且能正确识别跨180°的xlim范围。
  • 调整经纬线标注:根据目标范围修改了x_lines,确保标注只显示关键的120°E、180°、120°W、60°W,避免多余标注。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 17:02:47