【发布时间】:2020-02-13 04:48:10
【问题描述】:
当我尝试将点图层添加到geom_sf() 图层和投影时,这些点似乎最终位于德克萨斯州南部的一个位置。以下是重现此问题的最小示例。
library(sf)
library(ggplot2)
# devtools::install_github("hrbrmstr/albersusa")
library(albersusa)
crs_use = "+proj=laea +lat_0=30 +lon_0=-95"
d_points = data.frame(long = c(-110, -103, -84),
lat = c(45, 40, 41))
A = ggplot(data = usa_sf()) +
geom_sf() +
geom_point(data = d_points,
aes(x = long, y = lat),
color = "red", size = 5) +
theme_minimal() +
ggtitle("(A) right point position, wrong projection")
B = ggplot(data = usa_sf()) +
geom_sf() +
geom_point(data = d_points,
aes(x = long, y = lat),
color = "red", size = 5) +
coord_sf(crs = crs_use) +
theme_minimal() +
ggtitle("(B) right projection, wrong points using geom_point()")
C = ggplot() +
geom_sf(data = usa_sf()) +
geom_sf(data = st_as_sf(d_points,
coords = c("long", "lat"), crs = crs_use),
color = "red", size = 5) +
coord_sf(crs = crs_use) +
theme_minimal() +
ggtitle("(C) right projection, wrong points using geom_sf() points")
cowplot::plot_grid(A, B, C, nrow = 3)
我想使用自定义投影向美国地图添加点图层。但是,每当我使用投影时,我指定的点就会变成德克萨斯州东南部的一个奇怪位置,而不是我指定的位置。
感谢任何有关解决此问题的建议。谢谢!
【问题讨论】:
-
请注意,目前有一个 ggplot 的 PR 可以使这更容易:github.com/tidyverse/ggplot2/pull/3659
标签: r ggplot2 data-visualization geospatial sf