如何在 R 地图中的特定位置绘制数据点

How to plot data points at particular location in a map in R

我有一个如下所示的数据集:

   LOCALITY      numbers
1   Airoli          72
2   Andheri East    286
3   Andheri west    208
4   Arya Nagar      5
5   Asalfa          7
6   Bandra East     36
7   Bandra West     72

我想在孟买地图中为数据集中的每个位置绘制气泡(数字越大,气泡越大)。

我使用 'maps' 库加载了孟买地图,但现在我不确定如何在地图上绘制这些地图。可以用 R 做吗?

我用它来加载地图:

library(ggmap)
library(mapproj)
maps <- get_map(location = 'Mumbai', zoom = 12)
ggmap(maps)

这应该会让您朝着正确的方向前进,但请务必查看@Jaap 在评论中指出的示例。

library(ggmap)

map <- get_map(location = "Mumbai", zoom = 12)

df <- data.frame(location = c("Airoli",
                              "Andheri East",
                              "Andheri West",
                              "Arya Nagar",
                              "Asalfa",
                              "Bandra East",
                              "Bandra West"),
                 values = c(72, 286, 208, 5, 7, 36, 72),
                 stringsAsFactors = FALSE)

locs_geo <- geocode(df$location)
df <- cbind(df, locs_geo)
df
#       location values      lon      lat
# 1       Airoli     72 72.99348 19.15793
# 2 Andheri East    286 72.87270 19.11549
# 3 Andheri West    208 72.82766 19.13632
# 4   Arya Nagar      5 80.32170 26.48341
# 5       Asalfa      7 72.89514 19.10023
# 6  Bandra East     36 72.84935 19.06053
# 7  Bandra West     72 72.83625 19.06069

ggmap(map) +
  geom_point(data = df, aes(x = lon, y = lat, size = values))