-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.R
228 lines (184 loc) · 9.73 KB
/
global.R
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# Packages ----------------------------------------------------------------
# Packages for Interactive Web application
library(shiny)
library(shinydashboard)
library(bs4Dash)
library(shinycssloaders)
library(shinyBS)
# Packages for Data Cleaning/Processing
library(tidyverse)
# Packages for Chart Creation
library(psrcplot)
library(plotly)
library(echarts4r)
# Packages for Table Creation
library(DT)
library(scales)
# Packages for Maps
library(sf)
library(leaflet)
# Package for Excel Data Creation
library(openxlsx)
wgs84 <- 4326
spn <- 32148
current_census_yr <- 2022
current_employment_yr <- 2023
census_years <- c(current_census_yr-10, current_census_yr-5, current_census_yr)
ofm_years <- c(2011, 2016, 2021, 2022)
pop_hsg_yrs <- c(2010, 2020, 2022, 2023)
hu_yrs <- c(2011, 2016, 2021, 2022, 2023)
industrial_years <- c(2010, 2015, 2020, 2022)
year_ord <- c("2023","2022","2021", "2020", "2019", "2018", "2017", "2016", "2015", "2014", "2013", "2012", "2011", "2010")
gtfs_year <- "2024"
gtfs_service <- "Spring"
# Run Modules files -------------------------------------------------------
module_files <- list.files('modules', full.names = TRUE)
sapply(module_files, source)
source("functions.R")
# Inputs ---------------------------------------------------------------
rgc_title <- "Regional Growth Center (12/12/2023)"
mic_title <- "MIC (1/5/2024)"
# Demographic Metrics
pop_hh_hu_data <- readRDS("data/pop_hsg_data.rds") |> mutate(data_year = factor(year, levels=year_ord))
unit_data <- readRDS("data/pop_hsg_data.rds") |>
mutate(data_year = factor(year, levels=year_ord)) |>
filter(grouping == "Housing Units" & year %in% hu_yrs) |>
group_by(geography) |>
mutate(delta = estimate-lag(estimate), data_year = paste0(lag(data_year),"-",data_year)) |>
as_tibble() |>
mutate(estimate = delta, concept = "New Net Housing Units") |>
drop_na() |>
select(-delta)
age_data <- readRDS("data/population_by_age.rds") |>
mutate(data_year = factor(year, levels=year_ord)) |>
mutate(geography = gsub("Greater Downtown Kirkland", "Kirkland Greater Downtown", geography)) |>
mutate(geography = case_when(
geography == "All Centers" & geography_type == rgc_title ~ "All RGCs",
geography == "All Centers" & geography_type == mic_title ~ "All MICs",
geography != "All Centers" ~ geography))|>
mutate(estimate = round(estimate, -1))
race_data <- readRDS("data/population_by_race.rds") |>
mutate(data_year = factor(year, levels=year_ord)) |>
mutate(geography = gsub("Greater Downtown Kirkland", "Kirkland Greater Downtown", geography)) |>
mutate(geography = case_when(
geography == "All Centers" & geography_type == rgc_title ~ "All RGCs",
geography == "All Centers" & geography_type == mic_title ~ "All MICs",
geography != "All Centers" ~ geography))|>
mutate(estimate = round(estimate, -1))
income_data <- readRDS("data/households_by_income.rds") |>
mutate(data_year = factor(year, levels=year_ord)) |>
mutate(geography = gsub("Greater Downtown Kirkland", "Kirkland Greater Downtown", geography)) |>
mutate(geography = case_when(
geography == "All Centers" & geography_type == rgc_title ~ "All RGCs",
geography == "All Centers" & geography_type == mic_title ~ "All MICs",
geography != "All Centers" ~ geography))|>
mutate(estimate = round(estimate, -1))
education_data <- readRDS("data/educational_attainment.rds") |>
mutate(data_year = factor(year, levels=year_ord)) |>
mutate(geography = gsub("Greater Downtown Kirkland", "Kirkland Greater Downtown", geography)) |>
mutate(geography = case_when(
geography == "All Centers" & geography_type == rgc_title ~ "All RGCs",
geography == "All Centers" & geography_type == mic_title ~ "All MICs",
geography != "All Centers" ~ geography))|>
mutate(estimate = round(estimate, -1))
employment_data <- readRDS("data/centers_employment.rds")
# Housing Data Metrics
tenure_data <- readRDS("data/households_by_tenure.rds") |>
mutate(data_year = factor(year, levels=year_ord)) |>
mutate(geography = gsub("Greater Downtown Kirkland", "Kirkland Greater Downtown", geography)) |>
mutate(geography = case_when(
geography == "All Centers" & geography_type == rgc_title ~ "All RGCs",
geography == "All Centers" & geography_type == mic_title ~ "All MICs",
geography != "All Centers" ~ geography))|>
mutate(estimate = round(estimate, -1))
type_data <- readRDS("data/housing_units_by_type.rds") |>
mutate(data_year = factor(year, levels=year_ord)) |>
mutate(geography = gsub("Greater Downtown Kirkland", "Kirkland Greater Downtown", geography)) |>
mutate(geography = case_when(
geography == "All Centers" & geography_type == rgc_title ~ "All RGCs",
geography == "All Centers" & geography_type == mic_title ~ "All MICs",
geography != "All Centers" ~ geography)) |>
mutate(estimate = round(estimate, -1))
burden_data <- readRDS("data/cost_burden.rds") |>
mutate(data_year = factor(year, levels=year_ord)) |>
mutate(geography = gsub("Greater Downtown Kirkland", "Kirkland Greater Downtown", geography)) |>
mutate(geography = case_when(
geography == "All Centers" & geography_type == rgc_title ~ "All RGCs",
geography == "All Centers" & geography_type == mic_title ~ "All MICs",
geography != "All Centers" ~ geography)) |>
mutate(estimate = round(estimate, -1))
renter_burden_data <- burden_data |> filter(concept == "Renter Cost Burden")
owner_burden_data <- burden_data |> filter(concept == "Owner Cost Burden")
# Transportation Metrics
mode_data <- readRDS("data/mode_to_work.rds") |>
mutate(data_year = factor(year, levels=year_ord)) |>
mutate(geography = gsub("Greater Downtown Kirkland", "Kirkland Greater Downtown", geography)) |>
mutate(geography = case_when(
geography == "All Centers" & geography_type == rgc_title ~ "All RGCs",
geography == "All Centers" & geography_type == mic_title ~ "All MICs",
geography != "All Centers" ~ geography)) |>
mutate(estimate = round(estimate, -1))
destination_mode_data <- readRDS("data/destination_mode_share.rds") |>
mutate(data_year = factor(year, levels=year_ord)) |>
filter(concept == "Work")
# Transit Data
transit_stop_data <- readRDS("data/transit_stop_data.rds")
transit_stop_lyr <- readRDS("data/transit_stop_lyr.rds")
transit_route_lyr <- readRDS("data/transit_route_lyr.rds")
# Centers Information
centers_info <- read_csv("data/centers_information.csv", show_col_types = FALSE)
intersection_density <- read_csv("data/center_intersection_density.csv", show_col_types = FALSE)
# Source information
source_info <- read_csv("data/source_information.csv", show_col_types = FALSE)
# Shapefiles --------------------------------------------------------------
rgc_shape <- readRDS("data/rgc_shape.rds") |> st_make_valid() |> st_transform(wgs84) |> rename(geometry="Shape")
rgc_names <- rgc_shape |> st_drop_geometry() |> select("name") |> arrange(name) |> distinct() |> pull()
random_rgc <- rgc_names[[sample(1:length(rgc_names), 1)]]
mic_shape <- readRDS("data/mic_shape.rds") |> st_make_valid() |> st_transform(wgs84) |> rename(geometry="Shape")
mic_names <- mic_shape %>% st_drop_geometry() %>% select("name") %>% arrange(name) %>% distinct() %>% pull()
random_mic <- mic_names[[sample(1:length(mic_names), 1)]]
# MIC Measures ------------------------------------------------------------
ord <- unique(c("Region", "All Centers", "All RGCs", "All MICs", mic_names))
vacancy_absorption <- read_csv("data/mic-vacancy-absorption.csv", show_col_types = FALSE)
land_ord <- c("Core Industrial", "Industrial-Commercial", "Aviation Operations",
"Military", "Total Industrial",
"Limited Industrial", "Non-Industrial*", "Total Gross Acreage",
"share")
industrial_land <- read_csv("data/mic-industrial-lands.csv", show_col_types = FALSE) |>
pivot_longer(cols = !c(year, geography, geography_type), names_to = "grouping", values_to = "estimate") |>
mutate(year = as.character(year)) |>
mutate(geography = case_when(
geography == "All Centers" & geography_type == rgc_title ~ "All RGCs",
geography == "All Centers" & geography_type == mic_title ~ "All MICs",
geography != "All Centers" ~ geography)) |>
mutate(geography = factor(geography, levels = ord)) |>
mutate(grouping = factor(grouping, levels = land_ord)) |>
arrange(geography, grouping, year) |>
filter(grouping != "share")
# Data for IL Pie Chart
industrial_land_shares <- industrial_land |>
filter(grouping %in% c("Total Industrial", "Limited Industrial", "Non-Industrial*", "Total Gross Acreage"))
total <- industrial_land_shares |> filter(grouping == "Total Gross Acreage") |> rename(total="estimate") |> select(-"grouping")
industrial_land_shares <- left_join(industrial_land_shares, total, by=c("year", "geography", "geography_type")) |>
mutate(share = estimate / total, estimate = round(estimate, 0)) |>
select(-"total") |>
filter(grouping != "Total Gross Acreage")
rm(total)
# Data for IL Table
total <- industrial_land |> filter(grouping == "Total Gross Acreage") |> rename(total="estimate") |> select(-"grouping")
industrial_land <- left_join(industrial_land, total, by=c("year", "geography", "geography_type")) |>
mutate(share = estimate / total, estimate = round(estimate, 0)) |>
select(-"total")
rm(total)
# Data for Industrial Jobs
industrial_jobs <- read_csv("data/mic-industrial-jobs.csv", show_col_types = FALSE) |>
filter(year %in% industrial_years) |>
mutate(year = as.character(year)) |>
mutate(geography = case_when(
geography == "All Centers" & geography_type == rgc_title ~ "All RGCs",
geography == "All Centers" & geography_type == mic_title ~ "All MICs",
geography != "All Centers" ~ geography)) |>
mutate(data_year = factor(year, levels=year_ord)) |>
filter(grouping %in% c("Industrial", "Non-industrial")) |>
mutate(geography = factor(geography, levels = ord)) |>
arrange(geography, grouping, year)