我想将共享颜色的颜色更改为不同的颜色,比如红色。到目前为止,我正在策划德国联邦州巴伐利亚和接触奥地利各州。我从country.html那里得到数据-
德国2级- sf.rds
德国1级- sf.rds
奥地利2级- sf.rds
奥地利1级- sf.rds
library("sf")
library("raster")
library("dplyr")
library("spData")
library("spDataLarge")
library("ggplot2")
library("patchwork")
library(tmap) # for static and interactive maps
library(ggpattern)
data_aut <- readRDS("~/plot_at_ger/data/gadm36_AUT_2_sf.rds")
data_ger <- readRDS("~/plot_at_ger/data/gadm36_DEU_2_sf.rds")
data_aut_high <- readRDS("~/plot_at_ger/data/gadm36_AUT_1_sf.rds")
data_aut_high <- data_aut_high[which(data_aut_high$NAME_1=='Salzburg' | data_aut_high$NAME_1=='Oberösterreich' | data_aut_high$NAME_1=='Tirol' | data_aut_high$NAME_1=='Vorarlberg'), ]
data_ger_high <- readRDS("~/plot_at_ger/data/gadm36_DEU_1_sf.rds")
data_ger_high <- data_ger_high[which(data_ger_high$NAME_1=='Bayern'), ]
ggplot() +
geom_sf(data = ger_selected_data_bavaria, fill = NA) +
geom_sf(data = aut_selected_data_rel, fill = NA) +
geom_sf(data = data_aut_high, fill = NA, size = 1, color = "grey35") +
geom_sf(data = data_ger_high, fill = NA, size = 1, color = "black") 这产生了以下数字:

有办法改变共享边框的颜色吗?
谢谢!
发布于 2021-12-14 13:46:44
在{sf} > 1.0的上下文中绘制共享边框有点棘手,因为它将s2依赖项用于球形操作,而s2库引入了半封闭多边形的新概念(这在GEOS年代是不存在的)。
有关详细信息,请参阅options.html#model。
无论如何,考虑一下这段代码,它构建在{giscoR}包上,用于访问EU坚果区域,并使用sf::st_intersection()查找共享边框。注意model = "closed"的使用(即所有多边形都包含它们的整个边界),这可能不是立即显而易见的,而且代码必须按预期工作。
library(dplyr)
library(ggplot2)
library(giscoR)
library(sf)
bavaria <- gisco_get_nuts(country = "DE",
nuts_level = "1") %>%
filter(NUTS_NAME == "BAYERN")
austria <- gisco_get_nuts(country = "AT",
nuts_level = "2")
shared_border <- st_intersection(bavaria,
austria,
model = "closed") # this line is important!
ggplot() +
geom_sf(data = bavaria, fill = NA, color = "gray40") +
geom_sf(data = austria, fill = NA, color = "gray40") +
geom_sf(data = shared_border, fill = NA, color = "red")

https://stackoverflow.com/questions/70349542
复制相似问题