【发布时间】:2020-03-07 11:01:27
【问题描述】:
我想根据 geojson 中定义的多边形来限制绘图,以便它只显示蓝色阴影区域 here。
即只需绘制内部的特征,包括环路。
geojson 可用here。
最好在边缘添加一个缓冲区以包括环路。
我绘制所有特征的代码(不受geojson限制)。
library(tidyverse)
library(osmdata)
bounding_box <- getbb("Birmingham", featuretype = "city")
streets <- bounding_box %>%
opq()%>%
add_osm_feature(key = "highway",
value = c("motorway", "trunk", "primary", "secondary", "tertiary")) %>%
osmdata_sf()
ggplot() +
geom_sf(data = streets$osm_lines,
inherit.aes = FALSE,
color = "grey",
size = 1) +
theme_void() +
theme(
plot.background = element_rect(fill = "white"),
legend.position = "none"
) +
coord_sf(xlim = c(-1.933, -1.869),
ylim = c(52.46, 52.496),
expand = FALSE)
【问题讨论】:
标签: r ggplot2 geospatial sf