小编Hei*_*zer的帖子

无法将 ggsn 比例尺添加到 ggplot

我正在尝试使用 ggsn::scalebar() 向 ggplot 地图添加比例尺,但是尽管尝试了许多不同的参数组合,但我总是遇到一些错误。这是我的地图的代码:

# load libraries
library(tidyverse)
library(viridis)
library(sp)
library(rgdal)
library(ggsn)

# data
my.data.df <- data.frame(value = c(-1.2269832, -1.0153486, -0.9581069, -1.1534667, -1.0139735, -0.8711997, -0.8618286, -0.8524683),
                         x = c(538127.3, 538129.3, 538125.3, 538127.3, 538129.3,538131.3, 538121.3, 538123.3),
                         y = c(1101055, 1101055, 1101053, 1101053, 1101053, 1101053, 1101051, 1101051))
bb <- data.frame(long = c(538107, 538142), lat = c(1101020.5, 1101058.5))


# make a map
my.map <- ggplot(my.data.df, aes(x=x, y=y, fill=value)) +
  geom_tile() +
  geom_path(data = lines, aes(x=long, y=lat, group=group), inherit.aes = FALSE) +
  scale_fill_viridis("Subsidence …
Run Code Online (Sandbox Code Playgroud)

r

6
推荐指数
1
解决办法
1313
查看次数

溶解穿过 180 度子午线的多边形的内部边界

world我正在尝试使用极坐标投影的数据集制作地图spData。一切看起来都很棒,除了俄罗斯境内有穿过 180 度子午线的内部边界,而且似乎st_union()不会溶解跨过该边界的多边形,至少在我使用它时是这样。如何消除边界以使它们不会显示在我的地图上?我更喜欢使用的答案sf

library(sf)
library(spData)
library(dplyr)
library(ggplot2)

# polygon to crop the countries to only the northernmost ones
crop_poly <- tibble(geometry = st_sfc(st_point(c(0, 90)),
                                      crs = 'EPSG:4326')) %>%
  st_sf() %>%
  st_transform(crs = 'EPSG:3413') %>%
  st_buffer(dist = 3909167) %>%
  smoothr::densify(n = 3) %>%
  st_transform(crs = 'EPSG:4326')

# crop the world dataset
world_north <- world %>%
  st_intersection(crop_poly) %>%
  st_transform(crs = 'EPSG:3413') %>%
  select(name_long, continent, region_un, subregion) %>%
  st_union(by_feature = TRUE) # this is the suggested …
Run Code Online (Sandbox Code Playgroud)

r r-sf

3
推荐指数
1
解决办法
166
查看次数

标签 统计

r ×2

r-sf ×1