在 R 地图中绘制用户所走的路径

Plotting the paths taken by users in maps in R

以下是我的数据,

Name    datetime             latitude    longitude  mode
A   2016-01-11 02:00:04 PST 40.07054    -76.288572  Cycle
A   2016-01-11 02:10:04 PST 39.82271579 -77.2300438 Cycle
A   2016-01-11 02:20:04 PST 39.83636098 -77.2061907 Cycle
B   2016-01-02 03:55:58 PST 40.009918   -75.188196  Car
B   2016-01-02 03:59:58 PST 39.94432271 -76.5933571 Car
B   2016-01-02 04:10:58 PST 39.91651225 -77.1641403 Car

我想绘制每个用户沿日期时间所走的路径。输出显示就像图中不同的路径,其中每条路径都针对一个用户,在每个纬度和经度中,显示日期和时间,并且沿着路径显示模式。我不确定如何在 R 中执行此操作。任何人都可以帮助我执行此操作吗?

以下是可重现的例子,

names = c('A','A','A','B','B','B')
datetime = c('2016-01-11 02:00:04 PST','2016-01-11 02:10:04 PST','2016-01-11 02:20:04 PST','2016-01-02 03:55:58 PST','2016-01-02 03:59:58 PST','2016-01-02 04:10:58 PST')
latitude = c(40.07054,39.82271579,39.83636098, 40.009918,39.94432271,39.91651225)
longitude = c(-76.288572, -77.2300438, -77.2061907,-75.188196, -76.5933571, -77.1641403)
mode = c('Bike','Bike','Bike','Car','Car','Car')
test = data.frame(names,datetime,latitude,longitude,mode)

任何人都可以帮助我或建议一些绘制此图的方法吗?

更新:

以下是我的尝试,

library(ggplot2)
library(ggmap)

map <- get_map(location = c(lon = mean(test$longitude), lat = mean(test$latitude)), zoom = 4, maptype = "satellite", scale = 2)

basicmap <- ggmap(map)

basicmap + geom_path(data=test,aes(x=longitude, y=latitude, group=names, color=route),size=1)

但是我得到了,

Don't know how to automatically pick scale for object of type function. Defaulting to continuous
Error in data.frame(x = c(-76.288572, -77.2300438, -77.2061907, -75.188196,  : 
  arguments imply differing number of rows: 6, 0

谢谢

names = c('A','A','A','B','B','B')
datetime = c('2016-01-11 02:00:04 PST','2016-01-11 02:10:04 PST','2016-01-11 02:20:04 PST','2016-01-02 03:55:58 PST','2016-01-02 03:59:58 PST','2016-01-02 04:10:58 PST')
latitude = c(40.07054,39.82271579,39.83636098, 40.009918,39.94432271,39.91651225)
longitude = c(-76.288572, -77.2300438, -77.2061907,-75.188196, -76.5933571, -77.1641403)
mode = c('Bike','Bike','Bike','Car','Car','Car')
test = data.frame(names,datetime,latitude,longitude,mode)

library("ggmap")
m <- get_map(location=c(lon=median(test$longitude), lat=median(test$latitude)), zoom=8)
ggmap(m) + geom_point(aes(x=longitude, y=latitude, color=mode), data=test) + 
  geom_line(aes(x=longitude, y=latitude, color=mode), data=test)

这会产生:

请花一些时间更改颜色、坐标轴和其他内容以使其更美观,但这应该能让您入门。