我正在用 R 复制xkcd 的“错误地图投影:ABS(经度)”。我有一个不错的开始,但我想以“正确”的方式进行。
在这里,我拿了一张世界地图并制作了一个带有水平反射的副本。然后我绘制两者并将观察窗口裁剪为正经度。
library(ggplot2)
library(sf)
library(rnaturalearth)
library(rnaturalearthdata)
world <- ne_countries(scale = "small", returnclass = "sf") |>
sf::st_as_sf() %>%
sf::st_set_crs(value = 4326)
# matrix multiplication to reflect longitude
world_rev <- st_geometry(world) * matrix(c(-1,0,0,1), 2, 2)
world2 <- world |>
st_set_geometry(world_rev) |>
sf::st_as_sf() |>
sf::st_set_crs(value = 4326)
ggplot() +
geom_sf(data = world, fill = "#336666", alpha = 0.5) +
geom_sf(data = world2, fill = "#663366", alpha = 0.5) +
coord_sf(xlim = c(0, 180), expand = 0)
Run Code Online (Sandbox Code Playgroud)
这样做的一个缺点是我似乎无法应用不同的预测。例如,如果我以
coord_sf(crs= "+proj=robin", xlim = c(0, 180), expand = 0)
Run Code Online (Sandbox Code Playgroud)
我得到一个空白的情节。有没有更强大的方法来创建反转对象?
有点接近,但仍然不理想:
library(ggplot2)
library(sf)
#> Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(rnaturalearth)
library(rnaturalearthdata)
world <- ne_countries(scale = "small", returnclass = "sf") |>
sf::st_as_sf() %>%
sf::st_set_crs(value = 4326)
# matrix multiplication to reflect longitude
world_rev <- st_geometry(world) * matrix(c(-1,0,0,1), 2, 2)
world2 <- world |>
st_set_geometry(world_rev) |>
sf::st_as_sf() |>
sf::st_set_crs(value = 4326)
sf_use_s2(use_s2 = FALSE)
#> Spherical geometry (s2) switched off
bbox_0_180 <- st_bbox(c(xmin = 0, ymin = -90, xmax = 180, ymax = 90), crs = 4326)
world_crp <- st_crop(world, bbox_0_180)
world2_crp <- st_crop(world2, bbox_0_180)
ggplot() +
geom_sf(data = world_crp, fill = "#336666", alpha = 0.5) +
geom_sf(data = world2_crp, fill = "#663366", alpha = 0.5) +
coord_sf(crs= "+proj=robin +lon_0=90", expand = FALSE) +
scale_x_continuous(breaks = seq(0,180,30))
Run Code Online (Sandbox Code Playgroud)

创建于 2023-07-27,使用reprex v2.0.2
你有空白情节
coord_sf(crs= "+proj=robin", xlim = c(0, 180), expand = 0)
Run Code Online (Sandbox Code Playgroud)
因为罗宾逊是投影的,单位是米,xlim也适用,你可以尝试这个:
coord_sf(crs= "+proj=robin", xlim = c(-18e6, 18e6), expand = 0)
Run Code Online (Sandbox Code Playgroud)