-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.Rmd
More file actions
121 lines (88 loc) · 4.47 KB
/
map.Rmd
File metadata and controls
121 lines (88 loc) · 4.47 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
---
title: "Visualize Transit Delay Data"
output:
html_document: default
html_notebook: default
---
#### This visualization was initiated at the Open Data Day Hackathon in Zürich, 4 March 2017.
#### The original delay data come from data collected by the Verkehrsbetriebe Zürich (VBZ) and are available pubically from the Open Data Portal of [Stadt Zürch Open Data](https://data.stadt-zuerich.ch/dataset?sort=score+desc%2C+metadata_modified+desc&tags=vbz)
#### You can find the source code and other files [here](https://github.com/OpenDataDayZurich2016/visualization_delays)
#### The data represent the number of delays at stops that are greater than a stated threshold. The delays are tallied based on the increment in delay that occurred at stops, independent of whether the vehicle arrived at the stop on time or not. Negative delays, in which a vehicle stayed at a stop for less than the planned elapsed time, and thereby made headway on the schedule, were not counted.
#### The source code can be easily modified to count delays greater than a threshold in both directions, or use a higher threshold, in minute increments, up to six minutes. All maps show data for one direction only. This could be modified in a mutate statement in adjusted\_stop\_delays.Rmd. One could also modify the criteria for counting delays by, for example, only counting events in which vehicles exceed the scheduled time of stops when they are not ahead of schedule. This would exclude events in which a vehicle arrives ahead of schedule, then stays at a stop until its scheduled departure. In the current visualization, such an even could potentially be counted as a delay, when the threshold of 1.5 minutes beyond scheduled length of stay is exceeded.
### ==================================================================
```{r include=FALSE}
library(tidyverse)
library(lubridate)
library(leaflet)
library(htmlwidgets)
library(htmltools)
```
```{r, include=FALSE}
lines <- c(2,7,9,10,14,33,72)
popup=c("stops","halt_lang")
# addtiles() function fix found here: https://github.com/rstudio/leaflet/issues/192
addTiles2 = function (map, urlTemplate = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
attribution = NULL, layerId = NULL, group = NULL, options = tileOptions()){
options$attribution = attribution
if (missing(urlTemplate) && is.null(options$attribution))
options$attribution = paste("© OpenStreetMap",
"contributors, CC-BY-SA")
invokeMethod(map, getMapData(map), "addTiles", urlTemplate,
layerId, group, options)
}
# This loop creates and saves a widget for each dataset specified in 'lines'
for (i in lines){
df <- read_csv(paste('../data/stop_delays2/stops_delays_52_weeks_line_',i,'.csv',sep='')) %>%
filter(!stops %in% c('DEP2','DEP4','DEP5','DEP6','DEP7','DEP8','GAR6','GAR9','FRAF07')) %>%
mutate(content = paste(stops,halt_lang,'count =',del_1_1,sep=" "))
pal <- colorBin(palette = "Reds", domain=df$del_1_1, 6, pretty = FALSE)
m <- leaflet(df) %>% addTiles2() %>% setView(lng=8.5402,lat=47.3778,zoom=12) %>%
addCircles(~lon,~lat,label = ~content, #~htmlEscape(content) # popup= ~halt_lang, goes in addCircles
radius = 150, stroke=TRUE,color="Black",weight=1, fillColor = pal(df$del_1_1),
fillOpacity = 0.8) %>%
addLabelOnlyMarkers(~lon,~lat,label = ~content)
m <- m %>%
addLegend("bottomright", pal=pal, values= ~del_1_1, title = 'Delays > 1 min', opacity =0.8) %>%
addScaleBar(position="bottomleft",scaleBarOptions(metric=TRUE,imperial=FALSE))
saveWidget(widget = m, file= paste("./line_",i,".html",sep=''),selfcontained = TRUE)
eval(parse(text = paste('m_',i,'<- m',sep='')))
}
```
## At which tram and bus stops do delays occur and accumulate?
### In each of the following 7 cases, the number of delays at a single stop greatly exceeds the count of delays at all other stops.
## Tram 2 Number of Delays
### Greater than 1 minute
```{r echo = FALSE}
m_2
```
## Tram 7 Number of Delays
### Greater that 1 minute
```{r echo= FALSE}
m_7
```
## Tram 9 Number of Delays
### Greater than 1 minute
```{r echo = FALSE}
m_9
```
## Tram 10 Number of Delays
### Greater than 1 minute
```{r echo = FALSE}
m_10
```
## Tram 14 Number of Delays
### Greater than 1 minute
```{r echo = FALSE}
m_14
```
## Bus 33 Number of Delays
### Greater than 1 minute
```{r echo = FALSE}
m_33
```
## Bus 72 Number of Delays
### Greater than 1 minute
```{r echo = FALSE}
m_72
```
This report was generated by the file map.Rmd by using the 'knit to html' option in RStudio