-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmapping.R
71 lines (56 loc) · 1.84 KB
/
mapping.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Mapping bus locations
# try using ggmap package
library(ggplot2)
library(ggmap)
mapdata = get_map(location = c(lon = median(vehicDF$Longitude),
lat = median(vehicDF$Latitude)),
color = "color", source = "google", maptype = "terrain", zoom = 10)
g1 = ggmap(mapdata, extent = "device", ylab = "latitude", xlab = "longitude")
g1 + geom_point(data = vehicsToDf(), aes(x = Longitude, y = Latitude), color = "red", size = 2)
# Try using leaflet package
# install.packages("leaflet")
library(leaflet)
library(htmltools)
busIcon <- makeIcon("data/icons/bus.png", iconWidth = 17, iconHeight = 17)
m = vehicsToDf() %>%
filter(Longitude > -74) %>%
leaflet() %>%
addTiles() %>%
addMarkers(~Longitude, ~Latitude, popup = htmlEscape(~Name), icon = busIcon)
m
# Try plotting a path taken by a bus, using accumulated data
load("data/busLocations/800.rda")
l800 <- locations800
head(l800)
length(unique(l800$VehicleId))
getRouteID(unique(l800RouteID))
l8 <- l800 %>%
mutate(LastUpdated = toTime(LastUpdated)) %>%
left_join(mostRtDetails, by = "RouteId")
head(l8)
glimpse(l8)
unique(l8$LongName)
l8 %>%
dplyr::filter(ShortName == "B43") %>%
leaflet() %>%
addTiles() %>%
addMarkers(~Longitude, ~Latitude, popup = htmlEscape(~LastUpdated), icon = busIcon)
# How often was the location updated?
b43 <- l8 %>%
dplyr::filter(ShortName == "B43")
tdifs = diff(b43$LastUpdated, units = "sec")
hist(as.numeric(tdifs))
qqnorm(tdifs)
head(l8$LastStop)
# Are the buses done running yet?
load("data/busLocations/3000.rda")
l3 <- locations3000 %>%
mutate(LastUpdated = toTime(LastUpdated))
vehicsToDf() %>%
filter(Longitude > -74) %>%
leaflet() %>%
addTiles() %>%
addMarkers(~Longitude, ~Latitude, popup = htmlEscape(~Name), icon = busIcon)
mostRtDetails %>%
dplyr::filter(RouteId == 20030)
getCurrentMessages()