r - 在 r 中使用 ggplot 添加点到 usmap

标签 r ggplot2 usmap

我能够用这个 tutorial 创建美国 map .当我尝试向它添加额外的点时,无论我输入什么数据,它们最终都在南达科他州。

library(ggplot2)
library(usmap)
testData <- data.frame(LATITUDE = 20.31557, LONGITUDE = -102.42547)
p <- plot_usmap( regions = "state") 
p + geom_point(data = testData, aes(x = LONGITUDE, y = LATITUDE), color = "red")

最佳答案

截至 美国 map 0.5.0 ,存在一个名为 usmap_transform 的新函数转换 data.frame匹配 usmap 使用的投影.

这是一个类似于您提供的数据的示例:

library(usmap)
library(ggplot2)

# Lat/Lon of Sioux Falls, SD
test_data <- data.frame(lon = -96.70, lat = 43.55)

transformed_data <- usmap_transform(test_data)

plot_usmap("states") + 
  geom_point(data = transformed_data, 
             aes(x = lon.1, y = lat.1), 
             color = "red",
             size = 3)

Plot showing a single red point on a US map, where Sioux Falls, SD is located

还有一个名为 Advanced Mapping 的新小插图这更详细地显示了这一点。

关于r - 在 r 中使用 ggplot 添加点到 usmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52911837/

相关文章:

R Shiny Leaflet addLegend() 指定标签顺序

r - 使用 `glue` 将一列中的变量替换为另一列中的变量

r - 中间有 y 轴的多面 ggplot

r - 使用facet_grid从ggplot中提取单个图

R如何使用断点指定自定义颜色渐变

r - 在美国 map 上绘制数值

r - 在数据表中查找和子集模式

r - 在 R 中写入 Excel 文件时创建粗体列名称(colname)

r - ggplot geom_point : how to set font of custom plotting symbols?

r - 使用 plot_usmap 包在 R 中创建 map