标签: ggspatial

如何使 geom_sf() 指向北?

我正在尝试为 R 和 ggplot 制作一个映射包,它允许用户使用十进制度数定义他们的数据,但会根据用户数据所在的位置使用适当的投影。我决定为此使用ggspatial包,因为它会自动转换坐标。ggspatial 包反过来使用sf包,该包受 ggplot 支持。

我使用北极极地立体投影来获取纬度 > 60 度的数据。投影是笛卡尔投影,以距离北极的米为坐标单位。当然,当我尝试在北极的太平洋一侧绘制此投影时,北方将指向下方(因为 y 坐标指向北极)。

如何使用coord_sfggplot将地图指向北方?如果没有合理的方法来做到这一点,你能提出解决这个问题的方法吗?

示例数据:

library(rnaturalearth)
library(sp)
library(raster)
library(sf)
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
library(ggplot2)
library(ggspatial)

# Get coastline data a example

dt <- rnaturalearth::ne_coastline()

# Clip and reproject the data to Arctic polar stereographic

clip_boundary <- sp::SpatialPolygons(
  list(sp::Polygons(
    list(sp::Polygon(
      data.frame(lon = c(-180, 180, 180, -180), lat = c(60, 60, 90, 90)))), ID = 1)
  ), proj4string = sp::CRS(sp::proj4string(dt))) …
Run Code Online (Sandbox Code Playgroud)

gis r ggplot2 r-sf ggspatial

6
推荐指数
0
解决办法
620
查看次数

如何使用 sf 真正计算球形 voronoi 图?

我想使用世界的球形性质(不是它的投影)制作带有 voronoi 镶嵌的世界地图,类似于使用 D3.js,但使用 R。

据我所知(“再见平坦的地球,欢迎 S2 球面几何”)该sf包现在完全基于该s2包并且应该按照我的需要执行。但我不认为我得到了预期的结果。一个可重现的例子:

library(tidyverse)
library(sf)
library(rnaturalearth)
library(tidygeocoder)

# just to be sure
sf::sf_use_s2(TRUE)

# download map 
world_map <- rnaturalearth::ne_countries(
                scale = 'small', 
                type = 'map_units',
                returnclass = 'sf')

# addresses that you want to find lat long and to become centroids of the voronoi tessellation 
addresses <- tribble(
~addr,
"Juneau, Alaska" ,
"Saint Petersburg, Russia" ,
"Melbourne, Australia" 
)

# retrive lat long using tidygeocoder
points <- …
Run Code Online (Sandbox Code Playgroud)

r geospatial ggplot2 r-sf ggspatial

6
推荐指数
3
解决办法
76
查看次数

标签 统计

ggplot2 ×2

ggspatial ×2

r ×2

r-sf ×2

geospatial ×1

gis ×1