r - 如何对齐谷歌地图经度纬度的ggmap CRS
问题描述
尽管有很多 CRS 预测等帖子,但我无法阻止我的城镇下沉。
如果我去谷歌地图并进-35.016, 117.878
入奥尔巴尼镇是旱地(如下图):
如果我在 R 中输入 lat/long 并尝试使用简单的功能包和 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()
基于此评论,使用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,但这没有用。
推荐阅读
- python - 如何过滤包含字典列表的字典
- r - 在第一个循环-R 处固定一个值
- spring - 如何在 Spring Data MongoRepository 中使用事务?
- python - Django/Python - 将文件从命令输出保存到 ImageField
- javascript - 由于 npm 未导航到不正确的目录,无法运行服务器。并找到 package.jason
- python - 将构建的字典类型转换为 TypedDict
- netsuite - 从 V1 用户事件调用 V2 模块
- c++ - 将字符串转换为类
- typescript - Jest 遇到了 NUXT 打字稿的意外标记
- beautifulsoup - 没有名为 'bs4' 的模块,已为 pip3 安装但无法导入