首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R中的USMap仅绘制一个点,而不考虑经度和纬度

R中的USMap仅绘制一个点,而不考虑经度和纬度
EN

Stack Overflow用户
提问于 2021-04-01 20:09:44
回答 2查看 84关注 0票数 1

我正在使用macOS Big Sur

这是我使用的简单代码--不管是哪个城市,我在地图上只得到一个点,以内布拉斯加州为中心。

代码语言:javascript
复制
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))

非常感谢您的帮助

EN

回答 2

Stack Overflow用户

发布于 2021-04-01 20:26:40

usmap包需要与您的坐标系不同的其他坐标系(这里已经解释过了:Add points to usmap with ggplot in r)

要解决此问题,您需要:

代码语言:javascript
复制
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))
票数 1
EN

Stack Overflow用户

发布于 2021-04-01 20:34:35

要扩展@BastienDucreux的答案,您还可以帮助ggplot识别坐标参考系,然后使用ggspatial包绘制这些点。

代码语言:javascript
复制
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) 

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66904254

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档