【发布时间】:2021-02-21 00:38:51
【问题描述】:
我正在尝试使用 ggplot 创建地图并在我的纬度/经度点上分层。
我毫无问题地创建了美国地图,但是当我在 geom_point lat/lon 位置分层时,美国地图会缩小并发生变化。有人可以指出为什么会这样吗?
stateData <- map_data('state')
head(stateData)
us <- fortify(stateData, region = 'region')
gg <- ggplot() + geom_map(data = us, map = us,
aes(x = long, y = lat, map_id = region, group = group),
fill = 'white', color = 'black', size = 0.25) +
coord_map('albers', lat0 = 39, lat1 = 45) +
theme_map()
gg + #add the data points with lon/lat declaring the columns
geom_point(data=new_datav2, aes(x=lon, y=lat), color='red', alpha=0.15)
postalCode county lat lon
94102 San Francisco County 37.77711868 -122.4196396
94102 San Francisco County 37.77711868 -122.4196396
94102 San Francisco County 37.77711868 -122.4196396
94102 San Francisco County 37.77711868 -122.4196396
94612 Alameda County 37.80508041 -122.2730713
94002 San Mateo County 37.51834106 -122.276207
94102 San Francisco County 37.77711868 -122.4196396
94102 San Francisco County 37.77711868 -122.4196396
94102 San Francisco County 37.77711868 -122.4196396
94612 Alameda County 37.80508041 -122.2730713
94102 San Francisco County 37.77711868 -122.4196396
94102 San Francisco County 37.77711868 -122.4196396
94102 San Francisco County 37.77711868 -122.4196396
94102 San Francisco County 37.77711868 -122.4196396
94102 San Francisco County 37.77711868 -122.4196396
94102 San Francisco County 37.77711868 -122.4196396
94102 San Francisco County 37.77711868 -122.4196396
94063 San Mateo County 37.48450089 -122.2277222
94102 San Francisco County 37.77711868 -122.4196396
94596 Contra Costa County 37.90118027 -122.0616226
94102 San Francisco County 37.77711868 -122.4196396
94704 Alameda County 37.86988068 -122.2705383
94612 Alameda County 37.80508041 -122.2730713
【问题讨论】:
-
你好 ZHX。我无法重现您的错误。无论有没有你的点,我都会得到相同的地图对齐方式。您从加载哪些包开始?
-
感谢您的回复。我加载了以下软件包(如果您需要其他信息或我的数据集,请告诉我: library(dplyr) library(maps) library(mapproj) library (ggplot2) library(tidyverse) library(scales) library(leaflet) library(plyr)库(ggridges) 库(hrbrthemes) 库(fmsb) 库(radarchart) 库(forcats) 库(ggthemes)
-
我正在运行 RStudio 1.4 和 R4.03。使用 Windows 10。
-
在使用 geom_point 之前和使用 geom_point 之后,请查看我编辑的帖子以获取我的屏幕链接。
标签: r ggplot2 maps geom-point