-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcali_viz.R
202 lines (150 loc) · 6.57 KB
/
cali_viz.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
library(tidyverse)
library(glue)
library(visdat)
library(here)
# Load Data ---------------------------------------------------------------
load(here::here("tidy_data", "cali_data.RData"))
## Check, always
cali_data %>% skimr::skim()
cali_data %>% vis_dat()
View(cali_data)
# Visualizations ----------------------------------------------------------
## Custom colors from RColorBrewer
my_four <- c("#1F78B4", "#A6CEE3", "#33A02C", "#B2DF8A")
### PER 100K people
g_one <-
cali_data %>%
ggplot( aes(x = status ,
y = per_100K,
fill = status)) +
geom_col() +
guides(fill = "none") +
scale_fill_manual(values = my_four)
g_one
g_one + labs(x = "Population Cohort", y = "Per 100,000 people",
title = "Covid Hospitalizations in CA",
subtitle = "CDC Data: 30-May-2021 to 20-Nov-2021",
caption = "Data Humanist, CC-By 4.0")
# Test out variable labeling
g_one +
scale_x_discrete(
labels=c( "Vaccinated\nPrior C19" ,
"Vaccinated\nNo C19",
"Unvaccinated\nPrior C19",
"Unvaccinated\nNo C19"
) ) +
labs(x = "Population Cohort", y = "Per 100,000 people",
title = "Covid Hospitalizations in CA",
subtitle = "CDC Data: 30-May-2021 to 20-Nov-2021",
caption = "Data Humanist, CC-By 4.0")
# These labels better suited
g_one +
scale_x_discrete(
labels = c( "YES Natural Immunity:\n YES Vax" ,
"NO Natural Immunity:\n YES Vax" ,
"YES Natural Immunity:\n NO Vax" ,
"NO Natural Immunity:\n NO Vax")
) +
labs(x = "Population Cohort", y = "Per 100,000 people",
title = "Covid Hospitalizations in CA",
subtitle = "CDC Data: 30-May-2021 to 20-Nov-2021",
caption = "Data Humanist, CC-By 4.0")
# Compare Natural immunity with Vaccinated, including NI
focus_cali <- cali_data %>%
filter(status != "UnVax_No_Prior") %>%
ggplot( aes(x =status ,
y = per_100K,
fill = status)) +
geom_col() + coord_flip() +
guides(fill = "none") +
scale_fill_manual(values = my_four) +
scale_x_discrete(
labels = c( "YES Natural Immunity:\n YES Vax" ,
"NO Natural Immunity:\n YES Vax" ,
"YES Natural Immunity:\n NO Vax" )
)
focus_cali
focus_cali + labs(x = "Population Cohort", y = "Per 100,000 people",
title = "Covid Hospitalizations in CA",
subtitle = "CDC Data: 30-May-2021 to 20-Nov-2021",
caption = "Data Humanist, CC-By 4.0")
# Compare Natural immunity with Vaccinated -- NO NI
hosp_contrast <- cali_data %>%
filter(status != "UnVax_No_Prior" , status != "Vax_Prior_C19" ) %>%
mutate(year = "CA") %>%
ggplot( aes(x =status ,
y = per_100K,
fill = status)) +
geom_col() + coord_flip() +
guides(fill = "none") +
scale_fill_manual(values = c("#A6CEE3", "#33A02C"),
labels=c("NO Natural Immunity: YES Vax" ,
"YES Natural Immunity: NO Vax") ) +
scale_x_discrete(
labels = c( "NO Natural Immunity:\n YES Vax" ,
"YES Natural Immunity:\n NO Vax" )
)
hosp_contrast + labs(x = "Population Cohort", y = "Per 100,000 people",
title = "Covid Hospitalizations in CA",
subtitle = "CDC Data: 30-May-2021 to 20-Nov-2021",
caption = "Data Humanist, CC-By 4.0")
## PERCENTAGES
per_graph <- cali_data %>%
mutate(year = "CA") %>%
ggplot( aes(x = year, y = host_per, fill = status)) +
geom_bar(position="stack", stat="identity") +
scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
labs(x = " CDC\nData", y = "Covid Hospitalizations (%)",
fill = "Cohort Status") +
coord_flip() +
theme(legend.position = c(0.5, 0.5) ) +
scale_fill_manual(values = my_four,
labels=c("YES Natural Immunity: YES Vax" ,
"NO Natural Immunity: YES Vax" ,
"YES Natural Immunity: NO Vax" ,
"NO Natural Immunity: NO Vax" ) )
per_graph
per_graph + labs(x = "CDC Data",
y = "Covid Hospitalizations (%)",
title = "Covid Hospitalizations in CA",
subtitle = "30-May-2021 to 20-Nov-2021",
caption = "Data Humanist, CC-By 4.0")
# Compare Natural immunity with Vaccinated, including NI
focus_per <- cali_data %>%
filter(status != "UnVax_No_Prior") %>%
mutate(year = "CA") %>%
ggplot( aes(x = year, y = host_per, fill = status)) +
geom_bar(position="stack", stat="identity") +
coord_flip() +
scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
labs(x = " CDC\nData", y = "Covid Hospitalizations (%)",
fill = "Cohort Status") +
theme(legend.position = c(0.5, 0.5) ) +
scale_fill_manual(values = my_four,
labels=c("YES Natural Immunity: YES Vax" ,
"NO Natural Immunity: YES Vax" ,
"YES Natural Immunity: NO Vax") )
focus_per + labs(x = "CDC Data",
y = "Covid Hospitalizations (%)",
title = "Covid Hospitalizations in CA",
subtitle = "30-May-2021 to 20-Nov-2021",
caption = "Data Humanist, CC-By 4.0")
# Compare Natural immunity with Vaccinated -- NO NI
deep_focus_one <- cali_data %>%
filter(status != "UnVax_No_Prior" , status != "Vax_Prior_C19" ) %>%
mutate(year = "CA") %>%
ggplot( aes(x = year, y = host_per, fill = status)) +
geom_bar(position="stack", stat="identity") +
coord_flip() +
scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
labs(x = " CDC\nData", y = "Covid Hospitalizations (%)",
fill = "Cohort Status") +
theme(legend.position = c(0.5, 0.5) ) +
scale_fill_manual(values = c("#A6CEE3", "#33A02C"),
labels=c("NO Natural Immunity: YES Vax" ,
"YES Natural Immunity: NO Vax") )
deep_focus_one + labs(x = "CDC Data", y = "Covid Hospitalizations (%)",
title = "Covid Hospitalizations in CA",
subtitle = "30-May-2021 to 20-Nov-2021",
caption = "Data Humanist, CC-By 4.0")
save.image("~/R_STUDIO/Covid/tidy_data/dashboard2_data.RData")