我在一个csv中有一系列来自墨西哥的纬度和经度点,我正在将其转换为一个sf
对象。
library(sf)
library(spData)
library(tibble)
# basemap
mx = world %>% filter(iso_a2 == 'MX')
# cast to WGS84
mx = st_transform(mx, crs='EPSG:4326')
# mypoints
mypoints = tibble(
latitude = c(19.46762, 32.63224, 18.94691, 19.28556, 18.92243),
longitude = c(-98.14863, -115.5587, -103.9721, -99.13365, -99.22217)
)
mypoints_geo = st_as_sf(mypoints, coords = c("longitude", "latitude"), crs = 'EPSG:4326')
# plot
plot(mx['iso_a2'], axes=T)
plot(mypoints_geo, pch = 3, col = 'red', add=T)
字符串
正如你在第一张图中看到的,这些点并不位于墨西哥;事实上,它们甚至看起来都不位于经纬度值所在的位置。我附加了另一张图,它来自我在geopandas
中使用的另一个实现,它工作正常。我需要如何修改R实现才能得到想要的结果?
我试过:
- 更改初始CRS并转换为WGS 84
- 执行情况
- 使用在线工具搜索点位置
- 或者使用
ggplot2
进行绘图。
预期的结果是上面这张图的实现。
1条答案
按热度按时间toiithl61#
我设法在ggplot上重现了这一点,这是我使用的代码:
字符串
输出:
的数据