简体   繁体   English

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

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

I have a dataset that looks like this: 我有一个如下所示的数据集:

   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

I want to plot bubbles (bigger the number bigger would be the bubble) inside the map of mumbai for each location in dataset. 我想在孟买地图内为数据集中的每个位置绘制气泡(气泡数量越大,气泡越大)。

I loaded the map of mumbai using 'maps' library but now I am not sure on how to plot these in the map. 我使用'maps'库加载了孟买地图,但现在我不确定如何在地图中绘制这些。 Is it possible to do in R ? R可以吗?

I used this to load the map: 我用它来加载地图:

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

在此输入图像描述

This should get you headed in the right direction, but be sure to check out the examples pointed out by @Jaap in the comments. 这应该让你朝着正确的方向前进,但一定要查看评论中@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))

地图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM