forked from billyc/ds-week-12
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.Rmd
87 lines (69 loc) · 2.14 KB
/
index.Rmd
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
---
title: "Accident data in Berlin, 2019"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
library(sf)
library(tidyverse)
library(tmap)
# 2019 accident data
raw_unfaelle <- read_csv2("unfaelle.csv", locale=locale(encoding="latin1"))
# Create sf object from X/Y coord columns. Lon/Lat is EPSG:4326
unfaelle <- st_as_sf(raw_unfaelle, coords=c("XGCSWGS84","YGCSWGS84"), crs=4326)
# Berlin neighborhoods
bezirke <- st_read("shp-bezirke/bezirke_berlin.shp")
```
Interactive Gallery
===========
Für die Valueboxen gibt es hier input <https://rmarkdown.rstudio.com/flexdashboard/using.html#value_boxes>
Column {data-width=500}
-----------------------------------------------------------------------
### Number of Accidents
```{r}
valueBox(nrow(unfaelle), icon = "fa-bicycle" )
```
### Number of Bicycle Accidents
```{r}
valueBox(5000, icon = "fa-bicycle", color = "warning" )
```
Column {data-width=500}
-----------------------------------------------------------------------
### Accident Locations
This is some **text** here
```{r}
# 1. Plot the dots themselves
tmap_mode("view") # tmap_mode("plot")
#tm_basemap("OpenStreetMap.DE") +
unfaelle <- mutate(unfaelle, bike_related=IstRad==1)
tm_shape(bezirke) +
tm_polygons() +
tm_shape(unfaelle) +
tm_dots(size=0.01, col="bike_related", title="2019 Accidents: Bike-related?")
```
> Source data from: <https://www.statistik-berlin-brandenburg.de/>
### Collisions by neighborhood
```{r}
unfaelle <- st_transform(unfaelle, crs=25833)
bezirke <- st_transform(bezirke, crs=25833)
joined_data <- st_join(bezirke, unfaelle["IstRad"])
accident_summary <- joined_data %>%
group_by(SCHLUESSEL) %>%
summarize(num_accidents=n())
tm_shape(bezirke) +
tm_polygons() +
tm_shape(accident_summary) +
tm_dots(size="num_accidents", col="num_accidents", title="Collisions by Neighborhood, 2019")
```
Column {data-width=300}
-----------------------------------------------------------------------
### Neigbhorhood summary data
```{r}
knitr::kable(accident_summary)
```
Discussion
==========
These graphs are based on data we collected from....