我有一张以北美为中心的北半球地图。我想在美国周围画一个红色的矩形(这是插图的一部分),但是,我似乎不能让geom_rect画这个矩形。有什么想法吗?
生成地图的代码:
library(ggplot2)
library(ggspatial)
library(sf)
library(rnaturalearth)
world <- rnaturalearth::ne_countries(scale = "medium",
returnclass = "sf")
ggplot(data = world) +
geom_sf() +
coord_sf(crs = "+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs") 这是我尝试使用的代码来获得美国周围的红色矩形,它不起作用:
ggplot(data = world) +
geom_sf() +
coord_sf(crs = "+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs") +
geom_rect(aes(xmin = -132, xmax = -69, ymin = 23, ymax = 49), color = "red", inherit.aes = FALSE)理想的地图应该如下所示

发布于 2021-07-06 03:02:19
您可以再添加一层geom_sf,并像这样提到它自己的坐标:
a <- st_as_sf(data.frame(plot_id = 1, lat = -100, long = 36),
coords = c("lat", "long"), crs = 4326)
ggplot(data = world) +
geom_sf() +
geom_sf(data = a, shape = 0, size = 35, color = "red", stroke = 2) +
coord_sf(crs = "+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs")您可以根据需要更改形状

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