尽管有很多CRS预测的帖子,等等,我无法阻止我的小镇沉没。
[如果我转到Google Maps并输入-35.016, 117.878
,则奥尔巴尼镇位于干旱土地上(如下图所示):
如果我在R中输入纬度/经度,并尝试使用简单的功能包和ggmap进行映射,则该城镇位于大海中:
library(tidyverse)
library(sf)
library(lwgeom)
library(ggmap)
lat <- c(-35.016)
lon <- c(117.878)
df <- tibble(lon,lat) %>% st_as_sf( coords = c("lon", "lat"), crs = 4326)
bbox_aus <- c(left = 113.338953078, bottom = -43.6345972634, right = 153.569469029, top = -10.6681857235)
ggmap_aus <- ggmap(get_stamenmap(bbox_aus, zoom = 5, maptype = "toner-background"))
ggmap_aus +
geom_sf(data = df, colour = "red" , size = 3, alpha = 0.5, inherit.aes = FALSE) +
# coord_sf(datum = sf::st_crs(4326)) +
labs(title = "Albany Sinking",
x = NULL,
y = NULL) +
theme_bw()
如果将geom_point()
与lon和lat分别用作x和y,则该方法有效。
df <- tibble(lon,lat) %>% st_as_sf( coords = c("lon", "lat"), crs = 4326,
remove = FALSE)
ggmap_aus +
geom_point(data = df, colour = "red", size = 3, alpha = 0.5,
aes(x = lon, y = lat)) +
# coord_sf(datum = sf::st_crs(4326)) +
labs(title = "Albany is saved",
x = NULL,
y = NULL) +
theme_bw()
基于this comment,将geom_point()
与x和y美学结合使用,与ggmap如何生成ggplot更加紧密地对齐。
[不幸的是,我不确定如何使它与geom_sf()
一起使用,后者使用geometry
列进行绘制。该链接的注释中有一些讨论,但是解决方案似乎是使用您已经尝试过的inherit.aes = FALSE
。
基于警告Coordinate system already present. Adding new coordinate system, which will replace the existing one.
,我认为ggmap对象的坐标系不是4326,但是我找不到如何访问它的坐标系。我确实尝试将df
重新投影到EPSG:3857,但这没有用。