当我使用 ggplot 进行正交投影时,某些多边形/国家/地区会消失。我可以让俄罗斯或美国消失!
library(tmap)
library(tidyverse)
library(sf)
data("World")
World %>% st_transform("+proj=robin") %>% ggplot() +
geom_sf(aes(fill=life_exp)) ## looks fine
World %>% st_transform("+proj=ortho") %>% ggplot() +
geom_sf(aes(fill=life_exp)) ## Russia is gone!
World %>% st_transform("+proj=ortho +lat_0=40") %>% ggplot() +
geom_sf(aes(fill=life_exp)) # Russia is back but US is gone!
这很奇怪!
这里有一个使用mapview的黑客:https://www.rdocumentation.org/packages/mapview/versions/2.11.0/topics/npts
library(lwgeom)
library(mapview)
# Fix polygons so they don't get cut in ortho projection
World <- st_cast(World, 'MULTILINESTRING') %>%
st_cast('LINESTRING', do_split=TRUE) %>%
mutate(npts = npts(geometry, by_feature = TRUE)) %>%
st_cast('POLYGON')
World %>% st_transform("+proj=ortho +lat_0=40") %>% ggplot() +
geom_sf(aes(fill=life_exp)) # Russia is back but US is gone!