geom_sf 和 ggplot:多边形在某些投影中消失

问题描述 投票:0回答:1

当我使用 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!

这很奇怪!

ggplot2 geospatial geom-sf
1个回答
0
投票

这里有一个使用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!
© www.soinside.com 2019 - 2024. All rights reserved.