Skip to content

Commit

Permalink
Accident data
Browse files Browse the repository at this point in the history
  • Loading branch information
GregorRyb committed Feb 8, 2021
1 parent a509001 commit da70614
Show file tree
Hide file tree
Showing 2 changed files with 5,163 additions and 61 deletions.
70 changes: 64 additions & 6 deletions index.Rmd
Original file line number Diff line number Diff line change
@@ -1,36 +1,94 @@
---
title: "Untitled"
title: "Accident data in Berlin"
output:
flexdashboard::flex_dashboard:
orientation: columns
orientation: column
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")
```

Column {data-width=650}
-----------------------------------------------------------------------

### My pretty chart
### Accidents location

```{r}
# Base map
# basemap <- read_osm(bezirke, ext=1.1)
# 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?")
```

Column {data-width=350}
-----------------------------------------------------------------------

### Chart B
### Colliciosn by neighbourhood

```{r}
# 2. Plot neighborhood totals
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")
tmap_save(tmap_last(), "ziggy.html")
```


> Source data from: <https:www.statistik-berlin-brandenburg.de>
Heading one
===========


Column {data-width=350}
-----------------------------------------------------------------------



### Chart C

```{r}
knitr:: kable(accident_summary)
```

Loading

0 comments on commit da70614

Please sign in to comment.