-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathzcta_vaccinations-new.R
1548 lines (1305 loc) · 55.8 KB
/
zcta_vaccinations-new.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
library(tidyverse)
library(lubridate)
library(readxl)
library(cowplot)
library(tidycensus)
## census_api_key("3deb7c3e77d1747cf53071c077e276d05aa31407", install = TRUE, overwrite = TRUE)
library(rmapzen)
library(sf)
mz_set_tile_host_nextzen(key = ("hxNDKuWbRgetjkLAf_7MUQ"))
theme_set(theme_minimal_grid())
options(tigris_use_cache = TRUE)
mycols1 <- c("#8c510a", "#01665e", "#f5f5f5")
mycols2 <- c("#c51b7d", "#4d9221", "#f7f7f7")
mycols3 <- c("#b2182b", "#2166ac", "#f7f7f7")
mycols4 <- c("#d73027", "#4575b4", "#ffffbf")
mycols5 <- c("#b2182b", "#4d4d4d", "#ffffff")
mycols6 <- c("#b35806", "#542788", "#f7f7f7")
###############################################################################
# Cross walks #
###############################################################################
## County <- MSA
msa <- read_csv("census/msainfo.csv")
msa_fips <- msa %>%
distinct(msa, county, state, fips) %>%
glimpse()
## CBG -> ZCTA crosswalk
zip_walk <- read_csv("census/ZCTA_CBG_MASTER_9_25_2020.csv") %>%
mutate(GEOID10 = str_pad(as.character(GEOID10), 5, "left", "0"),
ZIP_CODE = str_pad(as.character(ZIP_CODE), 5, "left", "0"),
county_fips = str_sub(cbg, 1, 5))
## ZIP (residential) -> ZCTA
zz <- zip_walk %>% select(ZCTA = GEOID10, ZIP_CODE) %>% distinct()
## ZCTA <- county
county <- read_csv("census/counties_basicdata.csv") %>% glimpse()
zip_walk2 <- zip_walk %>%
distinct(GEOID10, county_fips, PO_NAME, STATE) %>%
left_join(msa_fips, by = c("county_fips" = "fips"))
## SVI
svi <- read_csv("census/svi_per_zip_TX.csv") %>%
mutate(ZIP = as.character(ZIP))
glimpse(svi)
svi2 <- svi %>%
rename(ZIP_CODE = ZIP)
zz2 <- zz %>%
left_join(svi2 %>%
select(ZIP_CODE, SVI),
by = c("ZCTA" = "ZIP_CODE")) %>%
filter(!is.na(SVI))
zz3 <- zz %>%
left_join(svi2 %>%
select(ZIP_CODE, SVI)## ,
## by = c("ZCTA" = "ZIP_CODE")
) %>%
filter(!is.na(SVI))
###############################################################################
# State- and county-level vax data #
###############################################################################
state_files_full <- dir("data", full.names = TRUE)
mystatefile <- state_files_full[length(state_files_full)]
mystatefile
file_date <- mystatefile %>% str_sub(6, 15) %>% ymd()
as_of <- lubridate::stamp("Mar 1, 2021")(file_date-1)
state_data <- read_xlsx(mystatefile, sheet = "By County")
state_data[1, ] %>% as.data.frame()
## State-wide average
as.numeric(state_data[1, "People Fully Vaccinated"])/as.numeric(state_data[1, "Population, 16+"])
as.numeric(state_data[1, "People Vaccinated with at least One Dose"])/as.numeric(state_data[1, "Population, 16+"])
state_average <- as.numeric(state_data[1, "People Vaccinated with at least One Dose"])/as.numeric(state_data[1, "Population, 16+"])
state_average
###############################################################################
# Load in ZIP-level vax data #
###############################################################################
## File names (with and without the "data/" directory)
files_full <- dir("data_zip", full.names = TRUE)
files <- dir("data_zip", full.names = FALSE)
## Dates for each of the files
dates <- files %>% str_sub(1, 10) %>% ymd()
## Names of the sheets of each Excel file
sheet_names <- files_full %>% lapply(excel_sheets)
names(sheet_names) <- dates
sheet_names
## Most recent data
zip_data <- read_xlsx(files_full[length(files_full)], sheet = "By Zip Code")
zip_data %>% glimpse()
## Change column names
colnames(zip_data) <- c("ZIP_CODE", "doses_administered", "one_dose", "fully_vaccinated")
## Convert to numeric...
zip_data <- zip_data %>%
mutate(doses_administered = as.numeric(doses_administered),
one_dose = as.numeric(one_dose),
fully_vaccinated = as.numeric(fully_vaccinated))
## Add in the ZCTA (joined by residential ZIP)
glimpse(zip_data)
## NEW
myzz <- read_csv("census/Zip_to_zcta_crosswalk_2020.csv")
glimpse(myzz)
zip_data2 <- zip_data %>%
left_join(myzz) %>%
glimpse()
zip_data2 %>% filter(is.na(ZCTA))
sum(is.na(zip_data2$ZCTA))
## OLD...
## zip_data2 <- zip_data %>%
## left_join(zz) %>%
## glimpse()
## 28413
## Unknowns
zip_data2 %>% filter((ZIP_CODE %in% c("Invalid/Unknown"))) %>% glimpse() %>% pull(one_dose) %>% na.omit() %>% sum()
zip_data2 %>% filter((ZIP_CODE %in% c("Out of State"))) %>% glimpse() %>% pull(one_dose) %>% na.omit() %>% sum()
zip_data2 %>% filter(!(ZIP_CODE %in% c("Invalid/Unknown", "Out of State"))) %>% pull(one_dose) %>% na.omit() %>% sum()
## Sum vax data across ZCTAs
zip_data3 <- zip_data2 %>%
## glimpse() %>%
filter(!is.na(ZCTA)) %>%
group_by(ZCTA) %>%
summarize(
PO_NAME = names(which.max(table(PO_NAME))),
doses_administered = sum(doses_administered, na.rm=T),
one_dose = sum(one_dose, na.rm=T),
fully_vaccinated = sum(fully_vaccinated, na.rm=T)
) %>%
glimpse()
## Sum vax data across ZCTAs
## zip_data3 <- zip_data2 %>%
## ## glimpse() %>%
## filter(!is.na(ZCTA)) %>%
## group_by(ZCTA, SVI) %>%
## summarize(
## doses_administered = sum(doses_administered, na.rm=T),
## one_dose = sum(one_dose, na.rm=T),
## fully_vaccinated = sum(fully_vaccinated, na.rm=T)
## ) %>%
## glimpse()
###############################################################################
# Pull the ACS data #
###############################################################################
## Check for ACS vars
if (dir() %>% str_detect("acs2019_variables.csv") %>% any()) {
acs_vars <- read_csv("acs2019_variables.csv")
} else {
acs_vars <- load_variables("2019", "acs5")
write_csv(acs_vars, "acs2019_variables.csv")
}
acs_vars %>% glimpse()
acs_vars %>% distinct(concept)
## Population data by age
myvars <- c(
"B01001_001",
"B01001_003",
"B01001_004",
"B01001_005",
"B01001_006", ## male 15-17
"B01001_027",
"B01001_028",
"B01001_029",
"B01001_030", ## female 15-17
"B01002_001",
"B19013_001")
## Seniors
sr <- acs_vars %>% slice(20:25, 44:49) %>% glimpse() %>% pull(name)
## acs_vars %>%
## mutate(ROWNUM = row_number()) %>%
## filter(concept %>% str_detect("SEX BY AGE"),
## label %>% str_detect("!Male:", negate=TRUE)) %>%
## View()
acs_vars %>% filter(name %in% myvars)
acs_vars %>% filter(name %in% myvars[c(5, 9)])
## acs <- get_acs(geography = "zcta", variables = myvars,
## state = "TX", geometry = TRUE)
## acs_wide18 <- get_acs(geography = "zcta", variables = myvars,
## state = "TX", geometry = TRUE, output = "wide", year=2018)
## Get ACS data
acs_wide <- get_acs(geography = "zcta", variables = myvars,
state = "TX", geometry = TRUE, output = "wide")
acs_wide_sr <- get_acs(geography = "zcta", variables = sr,
state = "TX", geometry = TRUE, output = "wide")
## Check that ZIP coverage is the same
acs_wide %>% nrow()
acs_wide_sr %>% nrow()
## Caclulate total senior population
acs_wide_sr <- acs_wide_sr %>%
mutate(plus65 = rowSums(across(contains("B") & contains("E")))) %>%
glimpse()
## Rename income variable
acs_wide <- acs_wide %>%
rename(
median_incomeE = B19013_001E,
median_incomeM = B19013_001M,
)
## Check for coverage of ZIP codes
mean(acs_wide$GEOID %in% zip_data$ZIP_CODE)
mean(acs_wide$GEOID %in% zip_data3$ZCTA)
mean(zip_data3$ZCTA %in% acs_wide$GEOID)
## Sum up under-18 population
acs_wide2 <- acs_wide %>%
## mutate(B01001_030E = B01001_030)
mutate(fifteen_only = round(1/3 * B01001_006E + 1/3 * B01001_030E)) %>%
mutate(
under18 = rowSums(across(## contains(myvars[-c(1, 5, 9)]) &
## contains(myvars[-c(1, 5, 9)]) &
contains(paste0(myvars[-c(1)], "E")) &
## contains("fifteen") &
!contains("M") &
!contains("B01002") &
!contains("B19013") &
!contains("income"))),
under16 = rowSums(across(## contains(myvars[-c(1, 5, 9)]) &
## contains(myvars[-c(1, 5, 9)]) &
(contains(paste0(myvars[-c(1, 5, 9)], "E")) |
contains("fifteen")) &
!contains("M") &
!contains("B01002") &
!contains("B19013") &
!contains("income"))),
## adult_pop = B01001_001E - under18,
adult_pop = B01001_001E - under16,
adult_frac = adult_pop/B01001_001E) %>%
left_join(acs_wide_sr %>%
as.data.frame() %>%
select(GEOID, plus65)) %>%
mutate(adults_16_64 = adult_pop - plus65,
adults_65_plus = plus65) %>%
mutate(senior_frac = plus65 / adult_pop,
nonsenior_frac = adults_16_64 / (adult_pop) ) %>%
glimpse()
## acs_wide2 %>%
## filter(GEOID %in% zip_data3$ZCTA) %>%
## ggplot() +
## geom_sf(aes(fill=adult_frac,col=adult_frac)) +
## scale_fill_viridis_c() +
## scale_color_viridis_c()
###############################################################################
# Join ACS and vax data #
###############################################################################
zzsvi <- read_csv("census/zcta-svi-woody.csv") %>%
rename(SVI = RPL_THEMES) %>%
mutate(ZCTA = as.character(ZCTA))
glimpse(zzsvi)
## Join
vax <- acs_wide2 %>%
left_join(zip_data3, by = c("GEOID" = "ZCTA")) %>%
left_join(zzsvi,
## distinct(ZCTA, SVI),
by = c("GEOID" = "ZCTA")) %>%
filter(adult_pop > 0) %>%
mutate(coverage = one_dose / (adult_pop+1),
coverage_under18 = one_dose / (B01001_001E - under18 +1)) %>%
## left_join(zip_walk2 %>%
## filter(!is.na(msa)) %>%
## distinct(GEOID10, msa, .keep_all = TRUE) %>%
## ## distinct(GEOID10, PO_NAME, county_fips, county) %>%
## ## select(GEOID10, S)
## mutate(GEOID10 = as.character(GEOID10)),
## by = c("GEOID" = "GEOID10")) %>%
left_join(msa %>%
filter(state == "Texas") %>%
rename(COUNTY = county) %>%
select(msa, COUNTY)) %>%
glimpse()
## vax <- acs_wide2 %>%
## left_join(zip_data3, by = c("GEOID" = "ZCTA")) %>%
## left_join(zz2 %>%
## distinct(ZCTA, SVI),
## by = c("GEOID" = "ZCTA")) %>%
## filter(adult_pop > 0) %>%
## mutate(coverage = one_dose / (adult_pop+1),
## coverage_under18 = one_dose / (B01001_001E - under18 +1)) %>%
## left_join(zip_walk2 %>%
## filter(!is.na(msa)) %>%
## distinct(GEOID10, msa, .keep_all = TRUE) %>%
## ## distinct(GEOID10, PO_NAME, county_fips, county) %>%
## ## select(GEOID10, S)
## mutate(GEOID10 = as.character(GEOID10)),
## by = c("GEOID" = "GEOID10")) %>%
## glimpse()
nrow(acs_wide2 %>% filter(adult_pop > 0))
nrow(vax)
## Certain places have coverage >1, mostly because of small adult
## populations...
vax %>% filter(coverage > 1) %>% arrange(adult_pop)
## 77030 is the ZIP code for the Texas Medical Center in Houston
## See: https://goo.gl/maps/Us7pcbRVC13n6PjJA
vax %>% filter(PO_NAME == "Houston") %>% filter(coverage > 1)
###############################################################################
# Join in eligibility numbers #
###############################################################################
eli <- read_csv("census/tx-zip-codes-vaccine-eligibility-groups.csv")
## Round down eligible population
eli <- eli %>%
mutate(ZCTA5 = as.character(ZCTA5)) %>%
mutate_if(is.double, floor) %>%
glimpse()
## Rename columns
colnames(eli)[-1] <- paste0("phase_", colnames(eli)[-1])
colnames(eli) <- colnames(eli) %>% str_replace("\\+", "plus")
glimpse(eli)
## Attack rate estimates
attack <- read_csv("census/zip_attack_rates_20210329.csv") %>%
mutate(ZIP = as.character(ZIP))
glimpse(attack)
## Join vaccine data with eligible population
vax <- vax %>%
left_join(eli %>%
select(ZCTA5, contains("total")),
by = c("GEOID" = "ZCTA5")) %>%
## left_join(attack,
## by = c("GEOID" = "ZIP")) %>%
glimpse()
## Join in attack rates (for Austin area only...)
vax_atx <- vax %>%
left_join(attack,
by = c("GEOID" = "ZIP"))
###############################################################################
# Export ZIP data #
###############################################################################
## Export certain columns
vax_small <- vax %>%
mutate(state_average = state_average) %>%
select(ZCTA = GEOID,
PO_NAME,
county,
msa,
state,
total_pop = B01001_001E,
adult_pop,
under18_pop = under18,
doses_administered,
one_dose,
fully_vaccinated,
coverage_one_dose = coverage,
state_average_coverage_one_dose = state_average,
contains("phase"),
SVI)
glimpse(vax_small)
write_csv(vax_small, sprintf("map_data/%s zip_data_processed.csv", today()))
###############################################################################
# Get geometry for Austin #
###############################################################################
## GET ROADS MSA
get_vector_tiles <- function(bbox){
mz_box=mz_rect(bbox$xmin,bbox$ymin,bbox$xmax,bbox$ymax)
mz_vector_tiles(mz_box)
}
zip_geom <- vax %>% filter(PO_NAME == "Austin")
zcta_geom <- st_union(zip_geom$geometry)
load("census/roads.Rdata")
I35_2 <- st_crop(I35, zcta_geom)
US183_2 <- st_crop(US183, zcta_geom)
missing_183_2 <- st_crop(missing_183, zcta_geom)
###############################################################################
# Make plots for Austin #
###############################################################################
mycity <- "Austin"
## City averages
city_avg <- vax %>%
left_join(attack,
by = c("GEOID" = "ZIP")) %>%
filter(PO_NAME == mycity) %>%
filter(!is.na(attack_rate_mean)) %>%
mutate(infected = B01001_001E * attack_rate_mean) %>%
glimpse() %>%
summarize(SVI = mean(SVI),
total_pop = sum(B01001_001E),
total_infected = sum(infected),
infection_rate = total_infected / total_pop,
adult_pop = sum(adult_pop),
one_dose = sum(one_dose),
senior_frac = sum(plus65)/adult_pop,
nonsenior_frac=sum(adults_16_64)/adult_pop) %>%
mutate(coverage = one_dose / adult_pop) %>%
glimpse()
## Subset a city...
vax_sub <- vax %>%
filter(PO_NAME == mycity)
## Vaccine coverage by income
vax_sub %>%
ggplot() +
geom_point(aes(log(median_incomeE), coverage, col = B01002_001E), size=3, alpha=0.8) +
scale_color_viridis_c("Median age")
## Vaccine coverage by senior fraction
vax_sub %>%
ggplot() +
geom_point(aes(senior_frac, coverage, col = SVI), size=3) +
## scale_color_viridis_c("Social vulnerability") +
scale_color_distiller("Social vulnerability", palette="Spectral") +
scale_y_continuous(labels=scales::label_percent()) +
scale_x_continuous(labels=scales::label_percent()) +
labs(x="Percentage of senior residents", y = "Vaccine coverage") +
guides(color = guide_colorsteps(ticks=TRUE,barwidth = 12, barheight = 0.5)) +
theme_dark(base_size=16) +
theme(legend.position = "bottom")
vax_sub %>%
ggplot() +
geom_point(aes(SVI, coverage, col = senior_frac), size=3, alpha=0.8) +
scale_color_viridis_c("Percentage of senior residents", labels=scales::label_percent()) +
scale_y_continuous(labels=scales::label_percent()) +
## scale_x_continuous(labels=scales::label_percent()) +
labs(x="Social vulnerability")
## Burden estimates (for Austin)
burden <- read_csv("census/zip_class_new.csv") %>%
rename(GEOID = ZIP, burden = group) %>%
mutate(GEOID = as.character(GEOID)) %>%
glimpse()
## Join in burden
vax_sub2 <- vax_sub %>%
left_join(burden) %>%
left_join(attack,
by = c("GEOID" = "ZIP")) %>%
glimpse()
vax_sub2 <- vax_sub2 %>%
mutate(burden = ifelse(is.na(burden), "low burden", burden))
myplot_highlow <- vax_sub2 %>%
## filter(county == "Harris") %>%
## filter(PO_NAME == "Houston") %>%
filter(PO_NAME == "Austin") %>%
## filter(coverage<1) %>%
## filter(GEOID %in% myzips) %>%
## filter(coverage!=max(coverage)) %>%
glimpse() %>%
ggplot() +
geom_sf(aes(fill=burden, label=GEOID## , col=burden
), size=0.1) +
geom_sf(data = I35_2,
col = "grey10") +
geom_sf(data = missing_183_2,
col = "grey10") +
geom_sf(data = US183_2,
col = "grey10") +
## scale_fill_manual(values=c("purple", "green")) +
scale_fill_brewer("", palette = "Accent", direction = -1) +
theme_map() +
## annotate(geom="text", x=-97.8, y=30.5, label="US 183", size=5)+
## annotate(geom="text", x=-97.68, y=30.5, label="I-35", size=5) +
theme(legend.position = "top",
legend.title = element_text(face = "bold"))
myplot_highlow
ggsave("~/Desktop/burden_map.png")
vax_sub2 %>%
gg
vax_sub2 %>%
glimpse() %>%
## filter(coverage>0.2) %>%
filter(!is.na(SVI)) %>%
mutate(SVI_cat = ifelse(SVI < mean(SVI), "low", "high")) %>%
## group_by(burden) %>%
group_by(burden) %>%
summarize(coverage_mean_adult = sum(one_dose)/sum(adult_pop),
coverage_mean_total = sum(one_dose)/sum(B01001_001E),
attack_rate = mean(attack_rate_mean),
attack_rate_min = min(attack_rate_mean),
attack_rate_max = max(attack_rate_mean)) %>% glimpse()
myscatter <- vax_sub2 %>%
ggplot() +
geom_smooth(aes(SVI, coverage)) +
geom_point(aes(SVI, coverage,
col = attack_rate_mean## , col=B01002_001E
## , col = burden
),
size = 2.5## , alpha=0.5
) +
## scale_color_distiller(palette = "Spectral") +
scale_color_viridis_c("Cumulative infections", option="C", labels=scales::percent) +
scale_y_continuous(labels=scales::percent) +
labs(title = "Vaccine coverage vs. social vulnerability in Austin",
y = "Vaccine coverage (% of adult population with at >=1 dose)",
x = "Social vulnerability index (SVI; higher is more vulnerable)")
myscatter
ggsave(sprintf("figures/austin/png/%s-vaccine_svi_scatter.png", today()), myscatter,
width=6.5, height = 6.25, units = "in")
ggsave(sprintf("figures/austin/pdf/%s-vaccine_svi_scatter.pdf", today()), myscatter,
width=6.5, height = 6.25, units = "in")
vax_sub2 %>% glimpse()
vax_sub2$SVI %>% hist()
vax_sub2$SVI %>% summary()
mynum1 <- vax_sub2 %>%
filter(SVI <= 0.10962) %>%
pull(coverage) %>%
mean()
mynum2 <- vax_sub2 %>%
filter(SVI >= 0.50333) %>%
pull(coverage) %>%
mean()
mynum1
mynum2
mynum1-mynum2
vax_sub2()
vax_sub2$coverage %>% hist()
vax_sub2$coverage %>% summary()
0.50333 - 0.10962
mydfsub <- vax_sub2 %>%
as.data.frame() %>%
select(attack_rate_mean, vaccine_coverage=coverage, SVI, senior_frac) %>%
## select(-geometry) %>%
as.data.frame() %>%
glimpse()## %>%
## as.matrix()
GGally::ggpairs(mydfsub)
GGally::ggpairs(mydfsub) + theme_grey(base_size=16)
mydfsub <- mydfsub[, -4]
pairs(mydfsub[-is.na(mydfsub[, 1])])
mydfsub[-is.na(mydfsub[, 1])]
source("zcta_features.R")
myscatter2 <- vax_sub2 %>%
ggplot() +
geom_smooth(aes(attack_rate_mean, coverage),method="lm") +
geom_point(aes(attack_rate_mean, coverage,
col = SVI## , col=B01002_001E
## , col = burden
),
size = 2.5## , alpha=0.5
) +
## scale_color_distiller(palette = "Spectral") +
scale_color_viridis_c("Social vulnerability",
option="C") +
scale_y_continuous(labels=scales::percent) +
scale_x_continuous(labels=scales::percent) +
labs(## title = "Cumulative infections, vaccine coverage, & social vulnerability in Austin",
y = "Vaccine coverage",
x = "Cumulative infections") +
guides(color = guide_colorsteps(ticks=TRUE,barwidth = 12, barheight = 0.5)) +
## theme_cowplot() +
theme(legend.position = "bottom",
axis.title = element_text(face="bold"),
legend.title = element_text(face="bold"))
myscatter2
summary(lm(coverage ~ senior_frac, data = vax_sub2))
summary(lm(coverage ~ attack_rate_mean, data = vax_sub2))
summary(lm(coverage ~ SVI, data = vax_sub2))
summary(lm(coverage ~ SVI + senior_frac, data = vax_sub2))
summary(lm(coverage ~ senior_frac + SVI , data = vax_sub2))
summary(lm(coverage ~ senior_frac + SVI, data = vax_sub2))
## summary(lm(coverage ~ senior_frac * SVI, data = vax_sub2))
summary(lm(coverage ~ SVI + senior_frac + attack_rate_mean, data = vax_sub2))
mylm <- lm(coverage ~ SVI + senior_frac + attack_rate_mean, data = vax_sub2)
xtable(mylm)
plot(vax_sub2$SVI, vax_sub2$coverage)
ggsave(sprintf("figures/austin/png/%s-vaccine_svi_scatter.png", today()), myscatter2,
width=6, height=4.5## ,
## width=6.75, height = 6.25, units = "in"
)
ggsave(sprintf("figures/austin/pdf/%s-vaccine_svi_scatter.pdf", today()), myscatter2,
width=6.75, height = 6.25, units = "in")
source("zcta_features.R")
## myplot2
myplot3 <- vax_sub2 %>%
## filter(county == "Harris") %>%
## filter(PO_NAME == "Houston") %>%
filter(PO_NAME == "Austin") %>%
## filter(coverage<1) %>%
## filter(GEOID %in% myzips) %>%
## filter(coverage!=max(coverage)) %>%
glimpse() %>%
ggplot() +
geom_sf(aes(fill=coverage, label=GEOID## , col=burden
), size=0.1) +
## geom_sf(data = travis_roads1,
## col = "grey30") +
## geom_sf(data = zcta_roads %>% filter(kind=="major_road"),
## col = "grey20") +
geom_sf(data = I35_2,
col = "grey10") +
geom_sf(data = missing_183_2,
col = "grey10") +
geom_sf(data = US183_2,
col = "grey10") +
## geom_sf(data = zcta_roads %>% filter(kind=="major_road"),
## col = "grey50") +
## scale_fill_viridis_c() +
## scale_color_viridis_c() +
## scale_fill_gradient2(sprintf("Vaccine coverage\n(%% of adult pop. with ≥1 dose)\ncity-average = %2.1f%%", city_avg$coverage * 100),
## midpoint=city_avg$coverage, labels=scales::percent,
## high = mycols3[2], low = mycols3[1], mid = mycols3[3]
## ## , mid="grey90"
## ## , low="firebrick3",high = "dodgerblue3"
## ) +
scale_fill_gradient2(## sprintf("Vaccine coverage"),
"",
## breaks=c(0.3, round(city_avg$coverage, 2), 0.5, 0.7, 0.9),
midpoint=city_avg$coverage, labels=scales::label_percent(accuracy=1),
high = mycols3[2], low = mycols3[1], mid = mycols3[3]
## , mid="grey90"
## , low="firebrick3",high = "dodgerblue3"
) +
## scale_fill_steps2( "",
## ## breaks=c(0.3, round(city_avg$coverage, 2), 0.5, 0.7, 0.9),
## midpoint=city_avg$coverage,## , mid="grey90"
## high = mycols3[2], low = mycols3[1], mid = mycols3[3],
## ## , low="firebrick3",high = "dodgerblue3"
## ## high = mycols1[1], low = mycols1[2], mid = mycols1[3],
## ## labels = scales::label_percent(accuracy=1),
## nice.breaks=FALSE
## ## low="darkorange", high="magenta", mid="grey95"
## ) +
NULL +
## labs(title = "Vaccine coverage in Austin",
## subtitle = sprintf("Percentage of adult population with at least one dose\nRelative to city-average (%2.1f%%)", city_avg$coverage * 100)) +
## guides(fill = guide_colourbar(barwidth = 0.5, barheight = 10)) +
## labs(caption=sprintf("Up to %s\nSource: Texas DSHS", as_of))+
labs(title="Vaccine coverage") +
guides(fill = guide_coloursteps(ticks=TRUE,barwidth = 12, barheight = 0.5)) +
## theme_cowplot() +
theme_map() +
## annotate(geom="text", x=-97.8, y=30.5, label="US 183", size=5)+
## annotate(geom="text", x=-97.68, y=30.5, label="I-35", size=5) +
theme(legend.position = "top",
legend.title = element_text(face = "bold"))
myplot3
myplot3_svi <- vax_sub2 %>%
## filter(county == "Harris") %>%
## filter(PO_NAME == "Houston") %>%
filter(PO_NAME == "Austin") %>%
## filter(coverage<1) %>%
## filter(GEOID %in% myzips) %>%
## filter(coverage!=max(coverage)) %>%
glimpse() %>%
ggplot() +
geom_sf(aes(fill=SVI), size=0.1) +
geom_sf(data = I35_2,
col = "grey10") +
geom_sf(data = missing_183_2,
col = "grey10") +
geom_sf(data = US183_2,
col = "grey10") +
## geom_sf(data = travis_roads1,
## col = "grey30") +
## geom_sf(data = travis_water3 %>%
## filter(name %>% str_detect("Lake") |
## name %>% str_detect("River")) ## %>%
## ## mutate(Area = st_area(geometry) %>% as.numeric()) %>%
## ## filter(Area > 1)
## ,
## aes(geometry = geometry2),
## fill = "lightblue", size = 0.1, col="lightblue")+
## scale_fill_viridis_c() +
## scale_color_viridis_c() +
scale_fill_gradient2(## sprintf("Social vulnerability"),
"",
midpoint=city_avg$SVI,## , mid="grey90"
## , low="firebrick3",high = "dodgerblue3"
## high = mycols1[1], low = mycols1[2], mid = mycols1[3]
low="darkgreen", high="darkviolet", mid="grey95"
) +
## scale_fill_gradient2(sprintf("Social vulnerability index\n(higher is more vulnerable)\ncity average = %1.2f", city_avg$SVI), midpoint=city_avg$SVI,## , mid="grey90"
## ## , low="firebrick3",high = "dodgerblue3"
## high = mycols1[1], low = mycols1[2], mid = mycols1[3]
## low="darkgreen", high="darkviolet", mid="grey95"
## ) +
NULL +
labs(## title = "Social vulnerability index in Austin",
## subtitle = sprintf("SVI by ZIP code\nRelative to city-average (%2.2f; higher is more vulnerable)", city_avg$SVI)
) +
## guides(fill = guide_colourbar(barwidth = 0.5, barheight = 10)) +
labs("\n") +
guides(fill = guide_coloursteps(ticks=TRUE,barwidth = 12, barheight = 0.5)) +
labs(title ="Social vulnerability") +
theme_map() +
## annotate(geom="text", x=-97.8, y=30.5, label="US 183", size=5)+
## annotate(geom="text", x=-97.68, y=30.5, label="I-35", size=5) +
## theme_cowplot() +
theme(legend.position = "top",
legend.title = element_text(face = "bold"))
myplot3_svi
myplot3_svi_mycols <- vax_sub2 %>%
## filter(county == "Harris") %>%
## filter(PO_NAME == "Houston") %>%
filter(PO_NAME == "Austin") %>%
## filter(coverage<1) %>%
## filter(GEOID %in% myzips) %>%
## filter(coverage!=max(coverage)) %>%
glimpse() %>%
ggplot() +
geom_sf(aes(fill=SVI), size=0.1) +
geom_sf(data = I35_2,
col = "grey10") +
geom_sf(data = missing_183_2,
col = "grey10") +
geom_sf(data = US183_2,
col = "grey10") +
## geom_sf(data = travis_roads1,
## col = "grey30") +
## geom_sf(data = travis_water3 %>%
## filter(name %>% str_detect("Lake") |
## name %>% str_detect("River")) ## %>%
## ## mutate(Area = st_area(geometry) %>% as.numeric()) %>%
## ## filter(Area > 1)
## ,
## aes(geometry = geometry2),
## fill = "lightblue", size = 0.1, col="lightblue")+
## scale_fill_viridis_c() +
## scale_color_viridis_c() +
scale_fill_gradient2(## sprintf("Social vulnerability"),
"",
midpoint=city_avg$SVI,## , mid="grey90"
## , low="firebrick3",high = "dodgerblue3"
high = mycols1[1], low = mycols1[2], mid = mycols1[3]
## low="darkgreen", high="darkviolet", mid="grey95"
) +
## scale_fill_steps2( "",
## breaks=c(0.2, round(city_avg$infection_rate, 1), 0.4, 0.6, 0.8),
## midpoint=city_avg$infection_rate,## , mid="grey90"
## ## , low="firebrick3",high = "dodgerblue3"
## high = mycols1[1], low = mycols1[2], mid = mycols1[3],
## ## labels = scales::label_percent(accuracy=1),
## nice.breaks=FALSE
## ## low="darkorange", high="magenta", mid="grey95"
## ) +
## scale_fill_gradient2(sprintf("Social vulnerability index\(higher is more vulnerable)\ncity average = %1.2f", city_avg$SVI), midpoint=city_avg$SVI,## , mid="grey90"
## ## , low="firebrick3",high = "dodgerblue3"
## high = mycols1[1], low = mycols1[2], mid = mycols1[3]
## low="darkgreen", high="darkviolet", mid="grey95"
## ) +
NULL +
labs(## title = "Social vulnerability index in Austin",
## subtitle = sprintf("SVI by ZIP code\nRelative to city-average (%2.2f; higher is more vulnerable)", city_avg$SVI)
) +
## guides(fill = guide_colourbar(barwidth = 0.5, barheight = 10)) +
labs(title="Social vulnerability") +
guides(fill = guide_coloursteps(ticks=TRUE,barwidth = 12, barheight = 0.5)) +
theme_map() +
## theme_cowplot() +
## annotate(geom="text", x=-97.8, y=30.5, label="US 183", size=5)+
## annotate(geom="text", x=-97.68, y=30.5, label="I-35", size=5) +
theme(legend.position = "top",
legend.title = element_text(face = "bold"))
myplot3_svi_mycols
myplot3_both <- plot_grid(myplot3, myplot3_svi, align="hv")
myplot3_both
ggsave(sprintf("figures/austin/png/%s-vaccine_coverage_svi_maps.png", today()), myplot3_both,
width = 11, height = 6.1, units="in")
ggsave(sprintf("figures/austin/pdf/%s-vaccine_coverage_svi_maps.pdf", today()), myplot3_both,
width = 11, height = 6.1, units="in")
myplot3_burden <- vax_sub2 %>%
## filter(county == "Harris") %>%
## filter(PO_NAME == "Houston") %>%
filter(PO_NAME == "Austin") %>%
## filter(coverage<1) %>%
## filter(GEOID %in% myzips) %>%
## filter(coverage!=max(coverage)) %>%
glimpse() %>%
ggplot() +
geom_sf(aes(fill=attack_rate_mean), size=0.1) +
geom_sf(data = I35_2,
col = "grey10") +
geom_sf(data = missing_183_2,
col = "grey10") +
geom_sf(data = US183_2,
col = "grey10") +
## geom_sf(data = travis_roads1,
## col = "grey30") +
## geom_sf(data = travis_water3 %>%
## filter(name %>% str_detect("Lake") |
## name %>% str_detect("River")) ## %>%
## ## mutate(Area = st_area(geometry) %>% as.numeric()) %>%
## ## filter(Area > 1)
## ,
## aes(geometry = geometry2),
## fill = "lightblue", size = 0.1, col="lightblue")+
## scale_fill_viridis_c() +
## scale_color_viridis_c() +
scale_fill_gradient2(## sprintf("Cumulative infections", city_avg$infection_rate * 100),
"",
midpoint=city_avg$infection_rate,## , mid="grey90"
## , low="firebrick3",high = "dodgerblue3"
high = mycols2[1], low = mycols2[2], mid = mycols2[3],
labels = scales::label_percent(accuracy=1)
## low="darkorange", high="magenta", mid="grey95"
) +
## scale_fill_steps2( "",
## breaks=c(0.2, 0.3, city_avg$infection_rate, 0.4, 0.5, 0.6),
## midpoint=city_avg$infection_rate,## , mid="grey90"
## ## , low="firebrick3",high = "dodgerblue3"
## high = mycols2[1], low = mycols2[2], mid = mycols2[3],
## labels = scales::label_percent(accuracy=1),
## nice.breaks=FALSE
## ## low="darkorange", high="magenta", mid="grey95"
## )+
## scale_fill_gradient2(sprintf("Cumulative infections\ncity average = %2.1f%%", city_avg$infection_rate * 100), midpoint=city_avg$infection_rate,## , mid="grey90"
## ## , low="firebrick3",high = "dodgerblue3"
## high = mycols2[1], low = mycols2[2], mid = mycols2[3],
## labels = scales::label_percent(accuracy=1)
## ## low="darkorange", high="magenta", mid="grey95"
## ) +
NULL +
labs(## title = "Social vulnerability index in Austin",
## subtitle = sprintf("SVI by ZIP code\nRelative to city-average (%2.2f; higher is more vulnerable)", city_avg$SVI)
) +
## guides(fill = guide_colourbar(barwidth = 0.5, barheight = 10)) +
labs(title="Cumulative infections") +
guides(fill = guide_coloursteps(ticks=TRUE,barwidth = 14, barheight = 0.5)) +
## theme_cowplot() +
theme_map() +
## annotate(geom="text", x=-97.8, y=30.5, label="US 183", size=5)+
## annotate(geom="text", x=-97.68, y=30.5, label="I-35", size=5) +
theme(legend.position = "top",
legend.title = element_text(face = "bold"),
legend.title.align = 0)
myplot3_burden
## myplot3_3 <- plot_grid(myplot3, myplot3_svi, myplot3_burden, align="hv", nrow=1)
myplot3_3 <- plot_grid(myplot3_svi, myplot3_burden, myplot3, align="hv", nrow=1)
myplot3_3_mycols <- plot_grid(myplot3_svi_mycols, myplot3_burden, myplot3, align="hv", nrow=1)
myplot3_3_mycols
ggsave(sprintf("figures/austin/png/%s-vaccine_coverage_svi_burden.png", today()), myplot3_3,
width = 11*3/2, height = 6.1, units="in")
ggsave(sprintf("figures/austin/png/%s-vaccine_coverage_svi_burden.tiff", today()), myplot3_3,
width = 11*3/2, height = 6.1, units="in")
ggsave(sprintf("figures/austin/png/%s-vaccine_coverage_svi_burden.pdf", today()), myplot3_3,
width = 11*3/2, height = 6.1, units="in")
ggsave(sprintf("figures/austin/png/%s-vaccine_coverage_svi_burden_new2.png", today()), myplot3_3_mycols,## ,
width = 10*2800/3000, height = 4, units="in"
)
ggsave(sprintf("figures/austin/png/%s-vaccine_coverage_svi_burden_new.png", today()), myplot3_3_mycols,
width = 11*3/2, height = 6.1, units="in")
ggsave(sprintf("figures/austin/png/%s-vaccine_coverage_svi_burden_new.tiff", today()), myplot3_3_mycols,
width = 11*3/2, height = 6.1, units="in")
ggsave(sprintf("figures/austin/png/%s-vaccine_coverage_svi_burden_new.pdf", today()), myplot3_3_mycols,
width = 11*3/2, height = 6.1, units="in")
## myplot3_3 <- plot_grid(myplot3, myplot3_svi, myplot3_burden, align="hv", nrow=1)
myplot3_3_tall <- plot_grid(myplot3_svi, myplot3_burden, myplot3, align="hv", ncol=1)
myplot3_3_mycols_tall <- plot_grid(myplot3_svi_mycols, myplot3_burden, myplot3, align="hv", ncol=1)
myplot3_3_tall
myplot3_3_mycols_tall
ggsave(sprintf("figures/austin/png/%s-vaccine_coverage_svi_burden_tall.png", today()), myplot3_3_tall,
width = 4.5, height = 11, units="in")
ggsave(sprintf("figures/austin/png/%s-vaccine_coverage_svi_burden_tall.tiff", today()), myplot3_3_tall,
width = 4.5, height = 11, units="in")
ggsave(sprintf("figures/austin/png/%s-vaccine_coverage_svi_burden_tall.pdf", today()), myplot3_3_tall,
width = 4.5, height = 11, units="in")
ggsave(sprintf("figures/austin/png/%s-vaccine_coverage_svi_burden_tall_new.png", today()), myplot3_3_mycols_tall,