寻找map_data('world')替代方案:覆盖南纬-90的南极地图数据集
推荐解决方案:使用rnaturalearth包的世界地图数据集
这是目前R生态中最常用的map_data('world')替代方案,数据集自带的南极洲范围覆盖至南纬-89.99,完全适配ggplot2绘图逻辑,操作门槛极低。
操作步骤
- 第一步:安装依赖包
install.packages(c("rnaturalearth", "rnaturalearthdata")) # 如果需要更高精度的边界数据,可额外安装 rnaturalearthhires 包
- 第二步:加载数据并绘图
library(ggplot2) library(rnaturalearth) library(sf) # 获取中等精度的世界国家矢量数据,返回sf格式可直接对接ggplot2 world <- ne_countries(scale = "medium", returnclass = "sf") # 测试点位 data <- data.frame(lat = -86, long = 0) # 绘图,无需手动指定group参数,适配所有ggplot2的图层逻辑 ggplot() + geom_sf(data = world, col = "grey", fill = NA) + geom_point(data = data, aes(y = lat, x = long), col = 'red')
兼容原有写法的转换方案
如果需要沿用原来map_data返回的普通数据框格式(非sf空间格式),可通过以下代码转换,完全兼容你原有geom_polygon的写法:
world_df <- world %>% st_coordinates() %>% as.data.frame() %>% rename(long = X, lat = Y, group = L2)
你可以通过以下代码验证南极洲的最低纬度:
world %>% filter(admin == "Antarctica") %>% st_coordinates() %>% as.data.frame() %>% pull(Y) %>% min() # 返回结果约为-89.9999,完全覆盖南纬-90附近的点位需求
内容的提问来源于stack exchange,提问作者MorrisseyJ
相关产品推荐
相关产品推荐

