我有一个由51个地理点组成的data.frame b
使用ggmap
包我试图在谷歌地图上显示点
首先,我使用边界框从谷歌下载地图:
p<-ggmap(get_map(location = c(left = min(b$coords.x1), bottom = min(b$coords.x2), right =max(b$coords.x1) , top = max(b$coords.x2))))
但是当我绘制地图时:
p+geom_point(aes(x=coords.x1, y=coords.x2),data=b, alpa=0.5, size=3)
我得到了下一个警告:
Removed 21 rows containing missing values (geom_point)
这是我的数据框:
>
b
coords.x1 coords.x2
1 12.51787 41.87951
2 12.47803 41.89199
3 12.48278 41.90599
4 12.47687 41.89861
5 12.49223 41.89021
6 12.47090 41.90332
7 12.46656 41.89767
8 12.48494 41.90068
9 12.45351 41.90665
10 12.47221 41.89556
11 12.48449 41.89064
12 12.50552 41.89576
13 12.47714 41.85862
14 12.49313 41.87940
15 12.45394 41.90217
16 12.45446 41.90305
17 12.45446 41.90305
18 12.49214 41.91421
19 12.48331 41.90093
20 12.49060 41.88977
21 12.48533 41.89242
22 12.48111 41.89503
23 12.48313 41.89385
24 12.47454 41.89958
25 12.47631 41.91145
26 12.48694 41.88833
27 12.47477 41.88356
28 12.50742 41.88401
29 12.46809 41.88218
30 12.52118 41.91346
31 12.49211 41.88647
32 12.51339 41.88052
33 12.51339 41.88052
34 12.49666 41.88929
35 12.47537 41.89831
36 12.47733 41.89943
37 12.48074 41.90128
38 12.47543 41.90618
39 12.47597 41.90692
40 12.47724 41.90568
41 12.46651 41.90308
42 12.46693 41.92834
43 12.47402 41.93220
44 12.53848 41.83618
45 12.47951 41.89143
46 12.47307 41.89916
47 12.47705 41.90555
48 12.47938 41.90352
49 12.47922 41.90470
50 12.47639 41.91081
51 12.49242 41.89481
答案 0 :(得分:3)
我通常遵循将数据提供给窗口&#39;的策略。来自make_bbox
的 f :
bbox <- ggmap::make_bbox(Long, Lat, data, f = 0.5)
map_loc <- get_map(location = bbox, source = 'google', maptype = 'terrain')
map <- ggmap(map_loc, extent = 'device', maprange=FALSE, darken = c(0.5, "white"))
另一种选择是设置不同的缩放因子:
map_loc <- get_map(location = c(lon = mean(data$lon), mean(data$lat)),
source = 'google', zoom = 14)
map <- ggmap(map_loc, extent = 'device')
使用缩放级别来获得所需的窗口区域