forked from laderast/craggy_2019
-
Notifications
You must be signed in to change notification settings - Fork 5
/
evictions.Rmd
94 lines (68 loc) · 2.88 KB
/
evictions.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
88
89
90
91
92
93
94
---
title: "Looking at Evictions"
author: "[Ted Laderas](https://github.com/laderast)"
date: "`r Sys.Date()`"
output:
github_document:
hard_line_breaks: no
toc: true
numbersections: true
vignette: >
%\VignetteIndexEntry{"evictions"}
%\VignetteEncoding{UTF-8}
%\VignetteEngine{knitr::rmarkdown}
---
This RMarkdown document gives you a head start by processing the data, and lets you visualize the data using `burro`.
Run this code block to install `burro` (Data exploration app)
```{r eval=FALSE}
install.packages("remotes")
remotes::install_github("laderast/burro")
# Install from the source repository,
# if you are not running in a fork of the craggy2019 project.
# remotes::install_github("pdxrlang/craggy_2019")
```
Once installed, run from here on...
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(burro)
library(tidyr)
library(dplyr)
library(janitor)
library(craggy2019)
```
## Looking at the `evictions` dataset
```{r}
evictions <- readr::read_csv(system.file("extdata", "evictions.csv", package = "craggy2019")) %>%
janitor::clean_names() %>%
mutate(low_flag = factor(low_flag), imputed=factor(imputed), subbed=factor(subbed)) %>%
mutate(parent_location = stringr::str_replace(parent_location, pattern = ", Washington", replacement = ""))
burro::explore_data(evictions)
```
```{r}
should_be_numeric <- c("estimated_number_foreclosures", "estimated_number_mortgages", "estimated_foreclosure_rate" , "total_90_day_vacant_residential_addresses","total_residential_addresses","estimated_90_day_vacancy_rate", "total_hicost_2004_to_2006_hmda_loans",
"total_2004_to_2006_hmda_loans",
"estimated_hicost_loan_rate",
"bls_unemployment_rate", "ofheo_price_change")
forclose_wa <- readr::read_csv(system.file("extdata", "forecloseWATract.csv", package = "craggy2019")) %>%
janitor::clean_names() %>% mutate_at(should_be_numeric, ~na_if(., "#NULL!")) %>% mutate_at(should_be_numeric, ~stringr::str_replace(., "%", "")) %>% mutate_at(should_be_numeric, as.numeric) %>% select(-county, -state, -sta)
burro::explore_data(forclose_wa)
```
## Explore King County Zillow Values
This one doesn't work - I will push fixes to `burro`.
```{r eval=FALSE}
king_zillow <- readr::read_csv(system.file("extdata", "king_zillow.csv", package = "craggy2019"))
burro::explore_data(king_zillow,outcome_var = NULL)
```
## One Night Counts
```{r}
one_night <- readr::read_csv(system.file("extdata", "oneNightCount.csv", package = "craggy2019")) %>% janitor::clean_names() %>% tidyr::gather("neighborhood", "count", -year, -location)
burro::explore_data(one_night)
```
```{r eval = FALSE}
# Sample code for grabbing spatial data
library(tigris)
options(tigris_use_cache = TRUE)
# Grab shape files for King county at the census tract level
king_spatial <- tracts(state = "WA", county = "King")
dat <- geo_join(spatial_data = king_spatial, evictions, by = "GEOID")
```