forked from billyc/ds-week-12
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
5,163 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
``` | ||
|
Oops, something went wrong.