-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.rmd
82 lines (69 loc) · 2.49 KB
/
README.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
---
title: "README.rmd"
author: "Ken Steif"
date: "11/11/2020"
output:
html_document:
keep_md: true
preserve_yaml: false
---
# Virginia Beach, Virginia EMS calls w/ geographic coordinates
This repo houses a now deprecated version of the [Virginia Beach EMS calls data](https://data.vbgov.com/dataset/ems-calls-for-service/resource/3e03dc00-a196-48ec-af62-0eaf028f5c27?inner_span=True) with XY coordinates.
Data from January, 2017 through February, 2018 are included. This dataset is used for a final project option in my course.
```{r 1_setup, echo = FALSE, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,results=TRUE, message = FALSE, warning=FALSE,
fig.align="center", cache=TRUE)
```
```{r}
library(sf)
library(tidyverse)
library(lubridate)
library(viridis)
source("https://raw.githubusercontent.com/urbanSpatial/Public-Policy-Analytics-Landing/master/functions.r")
```
```{r, cache=TRUE, results=FALSE}
dat <-
read.csv("https://raw.githubusercontent.com/urbanSpatial/VaBeachEMSData/main/VaBeach_EMS_with_coords_17_18.csv")
boundary <-
st_read("https://opendata.arcgis.com/datasets/82ada480c5344220b2788154955ce5f0_1.geojson") %>%
filter(!ZIP_CODE %in% c(23456,23457,27950,27927)) %>%
st_union() %>% st_sf()
```
```{r}
dat <-
dat %>%
filter(!is.na(X) & !is.na(Y)) %>%
st_as_sf(coords = c("X", "Y"), crs = 4326, agr = "constant") %>%
mutate(callDate = mdy_hm(CallDateandTime),
hour = hour(callDate)) %>%
.[boundary,]
```
```{r}
vaFishnet <- st_make_grid(boundary, .007) %>% st_sf() %>% rownames_to_column("id")
jawn <-
st_join(dat, vaFishnet) %>%
st_drop_geometry() %>%
group_by(id, hour) %>%
summarize(Count = n()) %>%
full_join(vaFishnet) %>%
spread(hour, Count, fill=0) %>%
st_sf() %>%
dplyr::select(-`<NA>`)
```
<br>
```{r, fig.width=10, fig.height=12}
gather(jawn, hour, Count, -geometry, -id) %>%
mutate(hour = fct_relevel(hour, as.character(0:23))) %>%
mutate(Count2 = case_when(Count == 0 ~ "0",
Count == 1 ~ "1",
Count >= 2 & Count <= 4 ~ "2-4",
Count >= 5 & Count <= 10 ~ "5-10",
TRUE ~ ">10")) %>%
mutate(Count2 = fct_relevel(Count2,"0","1","2-4","5-10",">10")) %>%
ggplot() +
geom_sf(aes(fill=Count2), colour=NA) +
facet_wrap(~hour, ncol = 4) +
scale_fill_viridis(discrete=T, name="Count") +
labs(title="EMS Calls by hour, Virginia Beach") +
mapTheme()
```