我正在使用macOS Big Sur
这是我使用的简单代码--不管是哪个城市,我在地图上只得到一个点,以内布拉斯加州为中心。
library(maps)
library(ggmap)
library(usmap)
library(ggplot2)
GeoLocations <- data.frame(City = c("Atlanta","Seattle"),
Latitude = c(33.45,47.37),
Longitude = c(-84.23,-122.2))
plot_usmap(regions ="state") +
geom_point(data = GeoLocations, aes(x = Longitude, y = Latitude))非常感谢您的帮助
发布于 2021-04-01 20:26:40
usmap包需要与您的坐标系不同的其他坐标系(这里已经解释过了:Add points to usmap with ggplot in r)
要解决此问题,您需要:
GeoLocations <- data.frame(Longitude = c(-84.23,-122.2),
Latitude = c(33.45,47.37)) #keeping only Longitude and Latitude columns
GeoLocations <- usmap_transform(GeoLocations) #transform coordinates
plot_usmap(regions ="state") + geom_point(data = GeoLocations, aes(x = Longitude.1, y = Latitude.1))发布于 2021-04-01 20:34:35
要扩展@BastienDucreux的答案,您还可以帮助ggplot识别坐标参考系,然后使用ggspatial包绘制这些点。
library(ggspatial)
plot_usmap(regions ="state") +
coord_sf(crs = usmap::usmap_crs()) +
ggspatial::geom_spatial_point(data = GeoLocations,
aes(x = Longitude, y = Latitude), crs = 4326)

https://stackoverflow.com/questions/66904254
复制相似问题