我正在try 制作一张罗宾逊投影 map ,该 map not以经度0为中心,并横跨180°线的两侧.

我的代码如下:

library("rnaturalearthdata")
world <- ne_countries(scale = "medium", returnclass = "sf")
robinson = "+proj=robin +lon_0=-90 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"
transformed = st_transform(world, robinson)
ggplot(data=transformed) + geom_sf(fill = "gray", colour = "black")+theme_bw()

这将生成该 map ,该 map 的方向是正确的,只是所有分割的边界都是"由内而外"的,并覆盖整个 map .

enter image description here

这是9年前的related question,但我希望随着最近的包更新,有一个不那么复杂的解决方案,它将允许我们使用geom_point()绘制我们的经纬度/经度数据点,而不需要额外的转换.

编辑#2:L.Tyrone的解决方案很适合我.要使用此方法绘制点,您必须将它们从数据框转换为具有相同坐标参考系的SF对象,否则经度/经度将被解释为米,最终与0,0无法区分:

# Transform with fake data...
fakedata=data.frame(lat=c(-10,-20,80),lon=c(45,-100,120),tag=c("indian","tropical","arctic"))
transpoint = st_as_sf(fakedata,coords=c("lon","lat"),crs=4326)
dtran = st_transform(transpoint,robinson)

然后,您可以通过将特殊的geometry=stat=声明添加到geom_point甚至geom_text_repel来绘制它们:

geom_point(data=dtran,aes(geometry=geometry,color=tag),stat="sf_coordinates") +
geom_text_repel(data=dtran,aes(geometry=geometry,label=tag),stat="sf_coordinates")

Final Result: successful plot of fake data onto map

推荐答案

在投影任何超过180的多边形之前,你需要将它们‘打断’.sf包中的st_break_antimeridian()函数是实现这一点的最简单方法.它将抛出一个警告,您可以安全地忽略该警告.

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

world <- ne_countries(scale = "medium", returnclass = "sf") %>%
  st_set_crs(4326)

robinson <- "+proj=robin +lon_0=-90 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"

world_robinson_90w <- world %>%
  st_break_antimeridian(lon_0 = -90) %>%
  st_transform(crs = robinson)

ggplot() +
  geom_sf(data = world_robinson_90w)

result

R相关问答推荐

卸载安装了BRM的模型发出的警告

更新合适的R mgcv::bam模型报告无效类型(关闭).'';错误

为什么当我try 在收件箱中使用合并功能时会出现回收错误?

如何删除R中除某些特定名称外的所有字符串?

无法将传奇添加到cowplot多情节中

基于不同组的列的相关性

获取列中值更改的行号

RStudio中相关数据的分组箱形图

par函数中的缩写,比如mgp,mar,mai是如何被破译的?

在R gggplot2中是否有一种方法将绘图轴转换成连续的 colored颜色 尺度?

如何在R中描绘#符号?

打印XTS对象

如何根据数据帧中的值从该数据帧中提取值?

提高圣彼得堡模拟的速度

在R中使用列表(作为tibble列)进行向量化?

填充图例什么时候会有点?

ArrangeGrob()和类似的替代方法不接受Grob列表.在Grid.Draw,返回:glist中的错误(...):仅允许在glist";中使用Grobs;

在R中,有没有什么方法可以根据一列中的多个值来过滤行?

R,将组ID分配给另一个观测ID变量中的值的组合

如何在给定的环境中找到函数的函数参数?