【发布时间】:2021-11-07 04:20:15
【问题描述】:
我有一个数据框,其中包含我想在美国东北部地图上绘制的湖泊的纬度和经度。我正在关注tutorial,了解如何创建和绘制地图。
我可以按照教程链接中的功能运行代码(如下)。
library (ggplot2)
library(sf)
library(rnaturalearth)
library(rnaturalearthdata)
library(rgeos)
world <- ne_countries(scale = "medium", returnclass = "sf")
(sites <- data.frame(longitude = c(-80.144005, -80.109), latitude = c(26.479005, 26.83)))
ggplot(data = world) +
geom_point(data = sites, aes(x = longitude, y = latitude), size = 4,
shape = 23, fill = "darkred") +
coord_sf(xlim = c(-88, -78), ylim = c(24.5, 33), expand = FALSE)
但是当我为包含美国新英格兰几个湖泊的纬度和经度列的数据集个性化代码时,我收到了错误:
我的经纬度数据框:
LAT_DD83 LON_DD83
23 41.37213 -71.56798
34 42.33589 -71.90907
39 41.51963 -71.76691
62 41.78447 -71.64064
76 43.93213 -70.62131
129 41.41433 -71.54638
我的代码:
ggplot(data = world) + geom_sf() +
geom_point(data = lat_lon, aes(x = LON_DD83, y = LAT_DD83), size = 4, shape = 23, fill = "darkred") +
coord_sf(xlim = c(-80, -65), ylim = c(40, 50), expand = FALSE)
收到错误:
#Error in st_cast.POINT(x[[1]], to, ...) : cannot create MULTILINESTRING from POINT
我不太明白这个错误是什么意思。我错过了什么?
【问题讨论】:
标签: r ggplot2 latitude-longitude