我使用 R 的 ggplot2 包制作了一张地图,并在其上可视化了 geom_path。现在,我想添加一些标记和一个箭头以显示路径的方向。对于箭头,有一个名为 grid 的包,它具有 arrow() 函数,但如果我在 geom_path 美学中使用此函数,它将为路径的每个点绘制箭头。所以,我只想画一个箭头(只有一个箭头),以便可视化路径的方向。第二个问题是如何在我的地图上添加一些标记。我读过有一个不错的包 RGoogleMaps,它允许这样做,但问题是我使用的是 ggplot2。知道如何在我的地图上添加箭头和标记吗?提前致谢!
这是我的代码:
require(move)
require(ggmap)
require(mapproj)
gps <- move(x=temp$GPS_x, y=temp$GPS_y,time=as.POSIXct(temp$GPS_timeDate, format="%d/%m/%Y %H:%M:%S", tz="UTC"), proj=CRS("+proj=longlat +ellps=WGS84"), animal='unknown', sensor='NoName')
gps_df <- as(gps, "data.frame")
m <- get_map(bbox(extent(gps)*1.1), source="osm", zoom=14)
ggmap(m)+geom_path(data=gps_df[1:nrow(soc_long),], aes(x=temp$GPS_x[1:nrow(soc_long)], y=temp$GPS_y[1:nrow(soc_long)],colour=soc_long$dsoc),size=1.5,lineend="round")+scale_color_gradient(low='green',high='red')
输出如下:
这是临时数据集的一部分:
GPS_timeDate GPS_x GPS_y
13/11/13 14:54:15 10.17936802 54.33073984
13/11/13 14:54:16 10.17936768 54.33073967
13/11/13 14:54:17 10.17936735 54.33073951
13/11/13 14:54:18 10.17936702 54.33073934
13/11/13 14:54:19 10.17936668 54.33073917
13/11/13 14:54:20 10.17936635 54.33073901
13/11/13 14:54:21 10.17936601 54.33073884
13/11/13 14:54:22 10.17936568 54.33073867
13/11/13 14:54:23 10.17936535 54.33073851
13/11/13 14:54:24 10.17936501 54.33073834
13/11/13 14:54:25 10.17936547 54.33073849
13/11/13 14:54:26 10.17936597 54.33073866
13/11/13 14:54:27 10.17936646 54.33073882
13/11/13 14:54:28 10.17936696 54.33073899
13/11/13 14:54:29 10.17936745 54.33073915
13/11/13 14:54:30 10.17936794 54.33073931
13/11/13 14:54:31 10.17936844 54.33073948
13/11/13 14:54:32 10.17936893 54.33073964
13/11/13 14:54:33 10.17936943 54.33073981
13/11/13 14:54:34 10.17936992 54.33073997
13/11/13 14:54:35 10.17936943 54.33074
13/11/13 14:54:36 10.17936875 54.33074
13/11/13 14:54:37 10.17936807 54.33074
13/11/13 14:54:38 10.17936739 54.33074
13/11/13 14:54:39 10.17936671 54.33074
13/11/13 14:54:40 10.17936603 54.33074
13/11/13 14:54:41 10.17936535 54.33074
13/11/13 14:54:42 10.17936467 54.33074
13/11/13 14:54:43 10.17936399 54.33074
soc_long 数据集的值用于颜色渐变:
dsoc
1 0.348334562
2 0.348334562
3 0.348334562
4 0.348334562
5 0.348334562
6 0.348334562
7 0.348334562
8 0.348334562
9 0.348334562
10 0.348334562
11 0.367477325
12 0.367477325
13 0.367477325
14 0.367477325
15 0.367477325
16 0.367477325
17 0.367477325
18 0.367477325
19 0.367477325
20 0.367477325
21 0.248041791
22 0.248041791
23 0.248041791
24 0.248041791
25 0.248041791
26 0.248041791
27 0.248041791
28 0.248041791
29 0.248041791
30 0.248041791
最后,以下品脱是我想作为标记添加到路径的点:
lat lon
54.31545667 10.168515
54.30135833 10.14450333
54.30305167 10.137645
54.3072 10.13840667
54.31827833 10.13377
54.32098833 10.12690667
54.32025833 10.12314
54.31826833 10.12340333
54.31540667 10.12799167
54.31492167 10.13006833