(如何)是否可以在具有 d3/透视视图的地球上绘制地理数据(例如多边形层),类似于这个图形在维基百科上?
我想要一个解决方案sf
and ggplot
大多数,但欢迎任何解决方案。
(我问这个主要是出于好奇,但由于我经常看到这样的图形,我想这个问题可能有用)
您可以使用正交投影sf
and ggplot2
投影到"+proj=ortho"
坐标参考系。
让海洋变蓝可能需要一些调整;我已经通过地球半径来缓冲空岛(灵感来自这个要点).
有关所使用的参数(即 lat_0 和 lon_0)的更多信息,请查看 PROJ 文档https://proj.org/operations/projections/ortho.html
对于更形象的示例,请考虑这段代码:
library(sf)
library(giscoR) # for the countries dataset only
library(ggplot2)
# projection string used for the polygons & ocean background
crs_string <- "+proj=ortho +lon_0=30 +lat_0=30"
# background for the globe - center buffered by earth radius
ocean <- st_point(x = c(0,0)) %>%
st_buffer(dist = 6371000) %>%
st_sfc(crs = crs_string)
# country polygons, cut to size
world <- gisco_countries %>%
st_intersection(ocean %>% st_transform(4326)) %>% # select visible area only
st_transform(crs = crs_string) # reproject to ortho
# one of the visible ones red (don't really matter which one :)
world$fill_color <- ifelse(world$ISO3_CODE == "DEU", "interesting", "dull")
# now the action!
ggplot(data = world) +
geom_sf(data = ocean, fill = "aliceblue", color = NA) + # background first
geom_sf(aes(fill = fill_color), lwd = .1) + # now land over the oceans
scale_fill_manual(values = c("interesting" = "red",
"dull" = "lightyellow"),
guide = "none") +
theme_void()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)