-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEquityAnalysisDashboard.Rmd
More file actions
157 lines (145 loc) · 5.03 KB
/
Copy pathEquityAnalysisDashboard.Rmd
File metadata and controls
157 lines (145 loc) · 5.03 KB
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
---
title: "San Mateo Extreme Heat Equity Analysis Dashboard"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
source_code: embed
---
<style>
.datatables{
overflow: auto;
}
</style>
```{r global, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(htmltools)
library(sf)
library(leaflet)
library(mapboxapi)
smc_indicator_cbgs_2019 <- readRDS("Exheat_Spring/smc_indicator_cbgs_2019.rds")
smc_thresholds_cbgs_df <- readRDS("SanMateo/new_exheat_tm_30yr_thresholds.rds")
smc_thresholds_cbgs_df_max <- readRDS("SanMateo/new_exheat_tm_30yr_thresholds_max.rds")
```
Inputs {.sidebar}
-------------------------------------
**Directions** Select which indicators you would like to see compared with extreme heat. Select Threshold Temperature (degrees Fahrenheit). Select whether you want to use extreme heat projections summarized as a maximum or an average across the ten models. Wait a couple of seconds and the plot will update. Finally, select whether you want to compare different extreme heat ranges by actual population size or by proportional break down.
```{r, context="server"}
indicator_options = c("Race", "Income", "Ethnicity", "Age")
selectInput(
"indicator",
label = "Indicator:",
choices = indicator_options,
selected = indicator_options[3]
)
```
```{r, context="server"}
threshold_options = c("90", "95", "100", "105", "110")
selectInput(
"threshold",
label = "Temperature Threshold:",
choices = threshold_options,
selected = threshold_options[2]
)
```
```{r}
summary_options = c("Average of Climate Models","Maximum of Climate Models")
selectInput(
"summary",
label = "Statistic Type: ",
choices = summary_options,
selected = summary_options[1]
)
```
```{r}
plot_options = c("Actual","Proportional")
selectInput(
"plot_option",
label = "Plot Type: ",
choices = plot_options,
selected = plot_options[1]
)
```
Row {data-height=600}
-----------------------------------------------------------------------
### {.no-padding}
```{r}
#plotOutput("plot")
```
```{r, context="server"}
renderPlot({
variable <- input$indicator
threshold <- input$threshold
summary <- input$summary
plot_option <- input$plot_option
smc_selected_threshold <-
smc_thresholds_cbgs_df %>%
dplyr::filter(threshold_temp %in% c(paste0("above_",threshold))) %>%
rename(
weighted_exheat = weighted_tm_ave,
geography_id = GEOID
)
if(summary == "Maximum of Climate Models") {
smc_selected_threshold <-
smc_thresholds_cbgs_df_max %>%
dplyr::filter(threshold_temp %in% c(paste0("above_",threshold))) %>%
rename(
weighted_exheat = weighted_tm_max,
geography_id = GEOID
)
}
variable_exheat_cbgs <-
smc_indicator_cbgs_2019 %>%
dplyr::filter(indicator_name == variable) %>%
left_join(smc_selected_threshold, by = c("CBG" = "geography_id")) %>%
dplyr::filter(!is.na(weighted_exheat))
variable_exheat_quantiles <-
as.data.frame(quantile(variable_exheat_cbgs$weighted_exheat, seq(0,1,length.out = 6),na.rm = T))
colnames(variable_exheat_quantiles) <- "qt"
variable_bin_names <-
c(paste0(round(variable_exheat_quantiles[2,],2), " or less"), paste0(round(variable_exheat_quantiles[2,],2)," to ",round(variable_exheat_quantiles[3,],2)), paste0(round(variable_exheat_quantiles[3,],2)," to ",round(variable_exheat_quantiles[4,],2)), paste0(round(variable_exheat_quantiles[4,],2)," to ",round(variable_exheat_quantiles[5,],2)),paste0(round(variable_exheat_quantiles[5,],2), " to ",round(variable_exheat_quantiles[6,],2)))
variable_exbins <-
variable_exheat_cbgs %>%
mutate(
exheat_bin = case_when(
weighted_exheat <= variable_exheat_quantiles[2,] ~ variable_bin_names[1],
weighted_exheat > variable_exheat_quantiles[2,] & weighted_exheat <= variable_exheat_quantiles[3,] ~ variable_bin_names[2],
weighted_exheat > variable_exheat_quantiles[3,] & weighted_exheat <= variable_exheat_quantiles[4,] ~ variable_bin_names[3],
weighted_exheat > variable_exheat_quantiles[4,] & weighted_exheat <= variable_exheat_quantiles[5,] ~ variable_bin_names[4],
weighted_exheat > variable_exheat_quantiles[5,] ~ variable_bin_names[5]
)
)
position_choice = "stack"
if(plot_option == "Proportional") {
position_choice = "fill"
}
ggplot(
variable_exbins %>%
group_by(indicator, exheat_bin) %>%
summarize(estimate = sum(estimate))
) + geom_bar(
aes(
x = exheat_bin %>% factor(levels = rev(variable_bin_names)),
y = estimate,
fill = indicator
),
stat = "identity",
position = position_choice
) +
labs(
x = paste0("Number of Days above ",threshold," degrees F"),
y = "Population",
title = paste0(variable," by extreme heat days (",threshold," degrees f)")
) +
coord_flip() +
theme(
legend.position = "bottom",
legend.direction = "vertical"
)
})
```
<!-- Row {data-height=400} -->
<!-- ----------------------------------------------------------------------- -->
<!-- ### {.no-padding} -->