-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEJSCREEN.R
3362 lines (3178 loc) · 133 KB
/
EJSCREEN.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
# Transportation related emissions and burdens from EPA's EJSCREEN and DART's on-road CO2 emissions
library(tidyverse)
library(sf)
library(tmap)
library(tmaptools)
library(maptools)
# library(raster)
library(rgdal)
library(RColorBrewer)
library(sp)
library(CGPfunctions) # for slope graphs
library(tigris)
options(tigris_class = "sf")
load("DATA/ne_layers.rds")
# Download EJSCREEN Data from EPA. See https://www.epa.gov/ejscreen/download-ejscreen-data for details.
download.file(
url = "ftp://newftp.epa.gov/EJSCREEN/2019/EJSCREEN_2019_USPR.csv.zip",
destfile = "DATA/EJSCREEN/EJSCREEN_2019_USPR.csv.zip")
download.file(
url = "ftp://newftp.epa.gov/EJSCREEN/2015/EJSCREEN_20150505.csv.zip",
destfile = "DATA/EJSCREEN/EJSCREEN_20150505.csv.zip")
# Unzip the file
unzip("DATA/EJSCREEN/EJSCREEN_2019_USPR.csv.zip", exdir = "DATA/EJSCREEN")
unzip("DATA/EJSCREEN/EJSCREEN_20150505.csv.zip", exdir = "DATA/EJSCREEN")
# Read in EJSCREEN Data, isolate variables, fix types, append date to names
EJSCREEN19 <- read_csv("DATA/EJSCREEN/EJSCREEN_2019_USPR.csv") %>%
filter(ST_ABBREV %in% ne_states) %>%
dplyr::select(ID,DSLPM,CANCER,RESP,PTRAF,OZONE,PM25) %>%
mutate_at(c("DSLPM","CANCER","RESP","PTRAF","OZONE","PM25"), as.numeric) %>%
rename_all(paste0, "_19")
EJSCREEN15 <- read_csv("DATA/EJSCREEN/EJSCREEN_20150505.csv") %>%
filter(ST %in% ne_states) %>%
dplyr::select(c(1:19,28:30,32,37:39)) %>%
mutate_at(c("dpm", "cancer", "resp"), as.numeric) %>%
rename_all(paste0, "_15")
# Join data frames and compute percent changes
EJSCREEN_15_19 <- left_join(EJSCREEN15,EJSCREEN19,
by = c("FIPS_15" = "ID_19")) %>%
mutate(OZONE_pctChange = (OZONE_19 - o3_15)/o3_15 * 100,
PM25_pctChange = (PM25_19 - pm_15)/pm_15 * 100,
PTRAF_pctChange = (PTRAF_19 - traffic.score_15)/traffic.score_15 * 100)
# clean up
rm(EJSCREEN15,EJSCREEN19)
# Import CO2 by block group from DARTE geodatabase. See https://daac.ornl.gov/cgi-bin/dsviewer.pl?ds_id=1735
onroadCO2 <- st_read(dsn = "DATA/DARTE/DARTE_v2.gdb/DARTE_v2.gdb",
layer = "DARTE_v2_blockgroup_kgco2_1980_2017") %>%
mutate(GEOID = as.character(GEOID))
# Compute CO2 by block group with percent change
# Read in DARTE Annual On-road CO2 Emissions on a 1-km Grid. See https://daac.ornl.gov/cgi-bin/dsviewer.pl?ds_id=1735
# view relevant tif tags embedded within a geotiff before openning it
# GDALinfo("traffic/onroad_2017.tif")
# load the data
# CO2_2017 <- raster("DATA/DARTE/onroad_2017.tif")
# CO2_1990 <- raster("DATA/DARTE/onroad_1990.tif")
#
# # Crop to New England
# # Create copy of ne_blkgrp_sf with same CRS
# ne_blkgrp_sf_lcc <- st_transform(ne_blkgrp_sf, proj4string(CO2_2017))
#
# # Crop raster to New England and convert kilograms/km2 to metric tons/km2
# CO2_2017ne_tons <- crop(CO2_2017, ne_blkgrp_sf_lcc) %>%
# `/`(1000)
# CO2_1990ne_tons <- crop(CO2_1990, ne_blkgrp_sf_lcc) %>%
# `/`(1000)
# # clean up
# rm(CO2_1990,CO2_2017)
#
# # To extract raster values, need to first address empty geometries in polygon layer
# # check for empty geometries
# any(is.na(st_dimension(ne_blkgrp_sf_lcc)))
# # identiy empty geometries
# empty_geo <- st_is_empty(ne_blkgrp_sf_lcc)
# # filter out empty geometries
# ne_blkgrp_sf_lcc <- ne_blkgrp_sf_lcc[!empty_geo,]
# # clean up
# rm(empty_geo)
#
# # Extract mean CO2 values within each block group to an spdf
# meanCO2_17 <- extract(CO2_2017ne_tons, as_Spatial(ne_blkgrp_sf_lcc),
# fun=mean, sp=TRUE, na.rm=TRUE, small=TRUE)
#
# meanCO2_90 <- extract(CO2_1990ne_tons, as_Spatial(ne_blkgrp_sf_lcc),
# fun=mean, sp=TRUE, na.rm=TRUE, small=TRUE)
# Map it
# tm_shape(meanCO2_17) + tm_fill("onroad_2017", style = "quantile")
# tm_shape(meanCO2_90) + tm_fill("onroad_1990", style = "quantile")
# Join CO2 values to EJSCREEN block groups
EJSCREEN_15_19 <- onroadCO2 %>%
as.data.frame() %>%
left_join(EJSCREEN_15_19, ., by = c("FIPS_15" = "GEOID"))
# clean up
rm(onroadCO2)
# Join EJSCREEN data to block groups with demographics
ne_blkgrp_sf <- left_join(ne_blkgrp_sf,EJSCREEN_15_19,
by = c("GEOID" = "FIPS_15"))
# Join EJSCREEN data to towns
ne_towns_sf <- ne_blkgrp_sf %>%
st_transform(., st_crs(ne_towns_sf)) %>%
st_join(., ne_towns_sf, largest = TRUE) %>%
dplyr::select(GEOID.y, DSLPM_19:kgco2_2017) %>%
mutate(AvgBlkAREA = as.numeric(st_area(.))) %>% # convert from 'units' to numeric
group_by(GEOID.y) %>%
summarize_if(is.numeric,
list(~ weighted.mean(., w=AvgBlkAREA, na.rm = TRUE))) %>%
as.data.frame() %>%
left_join(ne_towns_sf, ., by = c("GEOID" = "GEOID.y"))
# clean up
rm(EJSCREEN_15_19)
# Assemble state boundaries and select cities for mapping
# Download cartographic boundary file of states from tigris
ne_states_sf_cb <- states(cb = TRUE) %>%
st_as_sf() %>%
filter(STUSPS %in% ne_states)
# tm_shape(ne_states_sp) + tm_borders()
# Create point layer of state capitols for context
# Note cb=FALSE is necessary for extracting centroids from town polygons. Otherwise, if cb=TRUE, cannot extract centroids from multipolygon features.
ne_towns_sf_pts <- ne_towns_sf <- rbind_tigris(
lapply(
ne_states, function(x){
county_subdivisions(state = x, cb = FALSE)})) %>%
filter((NAMELSAD == "Boston city" & STATEFP == "25") |
(NAMELSAD == "Portland city" & STATEFP == "23") |
(NAMELSAD == "Hartford town" & STATEFP == "09") |
(NAMELSAD == "Providence city" & STATEFP == "44") |
(NAMELSAD == "Portsmouth city" & STATEFP == "33") |
(NAMELSAD == "Montpelier city" & STATEFP == "50")) %>%
st_centroid(of_largest_polygon = TRUE)
# save original and joined spatial files with demographics
save(ne_blkgrp_sf,
ne_blkgrp_sf90,
ne_tracts_sf,
ne_towns_sf,
ne_towns_sf_pts,
ne_states,
ne_states_sf_cb,
file = "DATA/ne_layers.rds")
# SUMMARY STATISTICS AND MAPS OF DEMOGRAPHICS/EJ INDICES BY REGION AND STATE
# Map of populations of concern for New England
# create a directory to save shapefiles
# dir.create("DATA/shapefiles")
# # download the zipped shapefile from MassGIS into shapefiles directory
# download.file(url = "http://download.massgis.digital.mass.gov/shapefiles/ne/newengland.zip",
# destfile = "DATA/shapefiles/newengland.zip")
#
# # unzip the downloaded shapefile into the shapefiles directory
# unzip(zipfile = "DATA/shapefiles/newengland.zip", exdir = "./DATA/shapefiles")
#
# # read in shapefile using sf::st_read
# ne_states_sf <- st_read(dsn = "DATA/shapefiles", layer = "NEWENGLAND_POLY")
#
# # Add state abbreviations to state layer for labeling
# state.names <- sort(as.character(unique(ne_states_sf$NAME)))
# state.names <- data.frame(
# state.abbrev = c("CT","ME","MA","NH","RI","VT"),
# state.names
# )
# ne_states_sf <- left_join(ne_states_sf, state.names,
# by = c("NAME" = "state.names"))
# NEW ENGLAND
# Minorities
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
summarize(Minorities = sum(minorityE),
PctMinorities = paste0(
round(sum(minorityE)/sum(totalpopE)*100,1),
"%"))
# Map data
# version 1
# tmap_mode("plot")
# tm_shape(ne_blkgrp_sf_DemoEJ, unit = "mi") +
# tm_fill("minority_pctE", style = "pretty", title = "Percent",
# legend.hist = TRUE,
# legend.is.portrait = FALSE) +
# tm_shape(ne_states_sf) + tm_borders(alpha = 0.4) +
# tm_compass(type = "arrow", position = c("left", "top"), text.size = 0.5) +
# tm_scale_bar(breaks = c(0, 50, 100), text.size = 0.5,
# position = c(0.2,0.005)) +
# tm_layout(title = "Minorities in New England\nby Census Block Group\n2013-2017", main.title.size = 0.8,
# legend.position = c(.6, .005),
# legend.height = 0.7,
# legend.title.size = 0.7,
# legend.hist.size = 0.5,
# legend.text.size = 0.5,
# legend.width = 0.8)
# Map of minorities
# version 2
tmap_mode("plot")
tm_shape(ne_blkgrp_sf_DemoEJ, unit = "mi") +
tm_fill("minority_pctE", style = "pretty", title = "Percent",
legend.hist = TRUE,
legend.is.portrait = FALSE) +
tm_shape(ne_states_sf_cb) + tm_borders(alpha = 0.4) +
tm_text("STUSPS", size = 0.7, remove.overlap = TRUE, col = "gray") +
tm_shape(ne_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black", xmod = 0.7, ymod = 0.2) +
tm_scale_bar(breaks = c(0, 50, 100), text.size = 0.5,
position = c(0.6,0.005)) +
tm_layout(title = "Minorities in New England\nby Census Block Group\n2013-2017", frame = FALSE, main.title.size = 0.8,
legend.outside = TRUE,
legend.title.size = 0.7,
legend.outside.position = c("right", "top"),
legend.hist.width = 0.9)
# Facet map of Minority by state
tm_shape(ne_blkgrp_sf_DemoEJ, unit = "mi") +
tm_fill("minority_pctE", style = "pretty", title = "Percent") +
tm_facets(by = "STATE") +
tm_shape(ne_states_sf_cb) + tm_borders(alpha = 0.4) +
tm_text("STUSPS", size = 0.7, remove.overlap = TRUE, col = "gray") +
tm_shape(ne_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black", xmod = 0.7, ymod = 0.2) +
tm_scale_bar(text.size = 0.5,
position = c(0.6,0.005)) +
tm_layout(title = "Minorities by Census \nBlock Group 2013-2017", frame = FALSE, main.title.size = 0.8,
legend.title.size = 0.7,
legend.hist.width = 0.9)
# Low Income
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
summarize(LowIncome = sum(num2povE),
PctLowIncome = paste0(
round(sum(num2povE)/sum(totalpopE)*100,1),
"%"))
tm_shape(ne_blkgrp_sf_DemoEJ, unit = "mi") +
tm_fill("pct2povE", style = "pretty", title = "Percent",
legend.hist = TRUE,
legend.is.portrait = FALSE) +
tm_shape(ne_states_sf) + tm_borders(alpha = 0.4) +
tm_text("state.abbrev", size = 0.7, remove.overlap = TRUE, col = "gray") +
tm_shape(ne_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black", xmod = 0.7, ymod = 0.2) +
tm_scale_bar(breaks = c(0, 50, 100), text.size = 0.5,
position = c(0.6,0.005)) +
tm_layout(title = "Low Income People in New \nEngland by Census Block Group\n2013-2017", frame = FALSE, main.title.size = 0.8,
legend.outside = TRUE,
legend.title.size = 0.7,
legend.outside.position = c("right", "top"),
legend.hist.width = 0.9)
# Facet map of Low Income by state
tm_shape(ne_blkgrp_sf_DemoEJ, unit = "mi") +
tm_fill("pct2povE", style = "pretty", title = "Percent") +
tm_facets(by = "STATE") +
tm_shape(ne_states_sf_cb) + tm_borders(alpha = 0.4) +
tm_text("STUSPS", size = 0.7, remove.overlap = TRUE, col = "gray") +
tm_shape(ne_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black", xmod = 0.7, ymod = 0.2) +
tm_scale_bar(text.size = 0.5,
position = c(0.6,0.005)) +
tm_layout(title = "Low Income People by \nCensus Block Group\n2013-2017", frame = FALSE, main.title.size = 0.8,
legend.title.size = 0.7,
legend.hist.width = 0.9)
# Less than HS Education
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
summarize(NoHSDip = sum(lthsE),
PctNoHSDip = paste0(
round(sum(lthsE)/sum(age25upE)*100,1),
"%"))
tm_shape(ne_blkgrp_sf_DemoEJ, unit = "mi") +
tm_fill("pct_lthsE", style = "pretty", title = "Percent",
legend.hist = TRUE,
legend.is.portrait = FALSE) +
tm_shape(ne_states_sf) + tm_borders(alpha = 0.4) +
tm_text("state.abbrev", size = 0.7, remove.overlap = TRUE, col = "gray") +
tm_shape(ne_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black", xmod = 0.7, ymod = 0.2) +
tm_scale_bar(breaks = c(0, 50, 100), text.size = 0.5,
position = c(0.6,0.005)) +
tm_layout(title = "Adults with Less than a High \nSchool Education in New \nEngland by Census Block Group\n2013-2017", frame = FALSE, main.title.size = 0.8,
legend.outside = TRUE,
legend.title.size = 0.7,
legend.outside.position = c("right", "top"),
legend.hist.width = 0.9)
# Facet map of Less than HS Education by state
tm_shape(ne_blkgrp_sf_DemoEJ, unit = "mi") +
tm_fill("pct_lthsE", style = "pretty", title = "Percent") +
tm_facets(by = "STATE") +
tm_shape(ne_states_sf_cb) + tm_borders(alpha = 0.4) +
tm_text("STUSPS", size = 0.7, remove.overlap = TRUE, col = "gray") +
tm_shape(ne_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black", xmod = 0.7, ymod = 0.2) +
tm_scale_bar(text.size = 0.5,
position = c(0.6,0.005)) +
tm_layout(title = "Adults with Less than a \nHigh School Education \nby Census Block Group\n2013-2017", frame = FALSE, main.title.size = 0.8,
legend.title.size = 0.7,
legend.hist.width = 0.9)
# Linguistically Isolated
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
summarize(NoEnglish = sum(eng_limitE),
PctNoEnglish = paste0(
round(sum(eng_limitE)/sum(eng_hhE)*100,1),
"%"))
tm_shape(ne_blkgrp_sf_DemoEJ, unit = "mi") +
tm_fill("eng_limit_pctE", style = "pretty", title = "Percent",
legend.hist = TRUE,
legend.is.portrait = FALSE) +
tm_shape(ne_states_sf) + tm_borders(alpha = 0.4) +
tm_text("state.abbrev", size = 0.7, remove.overlap = TRUE, col = "gray") +
tm_shape(ne_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black", xmod = 0.7, ymod = 0.2) +
tm_scale_bar(breaks = c(0, 50, 100), text.size = 0.5,
position = c(0.6,0.005)) +
tm_layout(title = "Linguistically Isolated Households \nin New England by Census \nBlock Group 2013-2017", frame = FALSE, main.title.size = 0.8,
legend.outside = TRUE,
legend.title.size = 0.7,
legend.outside.position = c("right", "top"),
legend.hist.width = 0.9)
# Facet map of Linguistically Isolated by state
tm_shape(ne_blkgrp_sf_DemoEJ, unit = "mi") +
tm_fill("eng_limit_pctE", style = "pretty", title = "Percent") +
tm_facets(by = "STATE") +
tm_shape(ne_states_sf_cb) + tm_borders(alpha = 0.4) +
tm_text("STUSPS", size = 0.7, remove.overlap = TRUE, col = "gray") +
tm_shape(ne_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black", xmod = 0.7, ymod = 0.2) +
tm_scale_bar(text.size = 0.5,
position = c(0.6,0.005)) +
tm_layout(title = "Linguistically Isolated Households \nby Census Block Group \n2013-2017", frame = FALSE, main.title.size = 0.8,
legend.title.size = 0.7,
legend.hist.width = 0.9)
# Over Age 64
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
summarize(Over64 = sum(over65E),
PctOver64 = paste0(
round(sum(over65E)/sum(totalpopE)*100,1),
"%"))
tm_shape(ne_blkgrp_sf_DemoEJ, unit = "mi") +
tm_fill("pct_over65E", style = "pretty", title = "Percent",
legend.hist = TRUE,
legend.is.portrait = FALSE) +
tm_shape(ne_states_sf) + tm_borders(alpha = 0.4) +
tm_text("state.abbrev", size = 0.7, remove.overlap = TRUE, col = "gray") +
tm_shape(ne_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black", xmod = 0.7, ymod = 0.2) +
tm_scale_bar(breaks = c(0, 50, 100), text.size = 0.5,
position = c(0.6,0.005)) +
tm_layout(title = "People Over Age 64 \nin New England by Census \nBlock Group 2013-2017", frame = FALSE, main.title.size = 0.8,
legend.outside = TRUE,
legend.title.size = 0.7,
legend.outside.position = c("right", "top"),
legend.hist.width = 0.9)
# Facet map of Over 64 by state
tm_shape(ne_blkgrp_sf_DemoEJ, unit = "mi") +
tm_fill("pct_over65E", style = "pretty", title = "Percent") +
tm_facets(by = "STATE") +
tm_shape(ne_states_sf_cb) + tm_borders(alpha = 0.4) +
tm_text("STUSPS", size = 0.7, remove.overlap = TRUE, col = "gray") +
tm_shape(ne_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black", xmod = 0.7, ymod = 0.2) +
tm_scale_bar(text.size = 0.5,
position = c(0.6,0.005)) +
tm_layout(title = "People Over Age 64\nby Census Block Group\n2013-2017", frame = FALSE, main.title.size = 0.8,
legend.title.size = 0.7,
legend.hist.width = 0.9)
# Under Age 5
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
summarize(Under5 = sum(under5E),
PctUnder5 = paste0(
round(sum(under5E)/sum(totalpopE)*100,1),
"%"))
tm_shape(ne_blkgrp_sf_DemoEJ, unit = "mi") +
tm_fill("pct_under5E", style = "pretty", title = "Percent",
legend.hist = TRUE,
legend.is.portrait = FALSE) +
tm_shape(ne_states_sf) + tm_borders(alpha = 0.4) +
tm_text("state.abbrev", size = 0.7, remove.overlap = TRUE, col = "gray") +
tm_shape(ne_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black", xmod = 0.7, ymod = 0.2) +
tm_scale_bar(breaks = c(0, 50, 100), text.size = 0.5,
position = c(0.6,0.005)) +
tm_layout(title = "Children Under Age 5 \nin New England by Census \nBlock Group 2013-2017", frame = FALSE, main.title.size = 0.8,
legend.outside = TRUE,
legend.title.size = 0.7,
legend.outside.position = c("right", "top"),
legend.hist.width = 0.9)
# Facet map of Under 5 by state
tm_shape(ne_blkgrp_sf_DemoEJ, unit = "mi") +
tm_fill("pct_under5E", style = "pretty", title = "Percent") +
tm_facets(by = "STATE") +
tm_shape(ne_states_sf_cb) + tm_borders(alpha = 0.4) +
tm_text("STUSPS", size = 0.7, remove.overlap = TRUE, col = "gray") +
tm_shape(ne_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black", xmod = 0.7, ymod = 0.2) +
tm_scale_bar(text.size = 0.5,
position = c(0.6,0.005)) +
tm_layout(title = "Children Under Age 5\nby Census Block Group\n2013-2017", frame = FALSE, main.title.size = 0.8,
legend.title.size = 0.7,
legend.hist.width = 0.9)
# SUMMARY STATISTICS AND MAPS OF POLLUTION MEASURES BY REGION AND STATE (MIGHT WANT TO SHOW PERCENTILES HERE; OR STYLE = QUANTILE)
# PM2.5 in New England
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
dplyr::select(pm_15, PM25_19) %>%
summary()
# Histogram of PM2.5 for New England
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
ggplot(aes(x = PM25_19)) + geom_histogram() +
theme_minimal() +
ggtitle(expression(atop(paste("Histogram of ", PM[2.5], " Concentrations by"), "Census Block Group across New England, 2016"))) +
xlab(expression(paste(PM[2.5]," (", mu, "g/", m^3, ")", sep = ""))) +
ylab("Number of Block Groups")
# Map of PM2.5 across New England
tm_shape(ne_blkgrp_sf_DemoEJ, unit = "mi") +
tm_fill("PM25_19", style = "quantile",
title = expression(paste
(PM[2.5]," (", mu, "g/", m^3, ")", sep = "")),
legend.hist = TRUE,
colorNA = NULL,
textNA = NULL,
legend.format=list(list(digits=2)),
legend.is.portrait = TRUE) +
tm_shape(ne_states_sf) + tm_borders(alpha = 0.4) +
tm_text("state.abbrev", size = 0.7, remove.overlap = TRUE, col = "gray") +
tm_shape(ne_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black", xmod = 0.7, ymod = 0.2) +
tm_scale_bar(breaks = c(0, 50, 100), text.size = 0.5,
position = c(0.6,0.005)) +
tm_layout(title = "Annual PM2.5 \nConcentrations\n2016",
frame = FALSE, main.title.size = 0.8,
legend.outside = TRUE,
legend.title.size = 0.8,
legend.outside.position = c("right", "top"),
legend.hist.width = 0.9)
# Hotspot map of PM2.5 across New England. Getis-Ord Gi Statistic looks at neighbors within a defined proximity to identify where either high or low values cluster spatially. Statistically significant hot-spots are recognised as areas of high values where other areas within a neighborhood range also share high values too.
library(spdep)
# Get rid of empty geometries and NAs, and convert to spdf
empty_geo <- st_is_empty(ne_blkgrp_sf_DemoEJ)
ne_blkgrp_sp_DemoEJ <- ne_blkgrp_sf_DemoEJ[!empty_geo,] %>%
dplyr::select(GEOID,PM25_19) %>%
# st_transform(., crs = 2163) %>% # convert to US National Atlas Equal Area
na.omit() %>%
as_Spatial()
# Calculate the Queen's case neighbors
neighborsQC <- poly2nb(ne_blkgrp_sp_DemoEJ, queen = TRUE)
# Calculate neighbors by distance
# creates centroid and joins neighbors within 0 and 150000 units
# neighborsDist <- dnearneigh(coordinates(ne_blkgrp_sp_DemoEJ),d1 = 0, d2 = 15000, longlat = TRUE)
# creates listw
# nb_lw <- nb2listw(nb, style = 'B')
# Compute neighbor weights
spdep::set.ZeroPolicyOption(TRUE)
listw <- nb2listw(neighborsQC, style = "W", zero.policy = TRUE)
# compute Getis-Ord Gi statistic
local_g <- localG(ne_blkgrp_sp_DemoEJ$PM25_19, listw)
local_g <- cbind(ne_blkgrp_sp_DemoEJ, as.matrix(local_g))
names(local_g)[3] <- "gstat"
# map the results
tm_shape(local_g, unit = "mi",) +
tm_fill("gstat",
palette = "-RdBu",
style = "pretty",
title = expression(paste("Getis-Ord ", G[i]^"*")),
showNA = FALSE, alpha = 0.3) +
tm_shape(ne_states_sf_cb) + tm_borders(alpha = 0.4) +
tm_text("STUSPS", size = 0.7, remove.overlap = TRUE, col = "gray") +
tm_shape(ne_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black", xmod = 0.7, ymod = 0.2) +
tm_scale_bar(breaks = c(0, 50, 100), text.size = 0.5,
position = c(0.6,0.005)) +
tm_layout(title = "Hot Spot Map of \nPM2.5 for\nNew England", frame = FALSE, main.title.size = 0.6,
legend.position = c(.8,.2),
legend.title.size = 0.7)
# boxplot of PM2.5 by state for 2016
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
ggplot(aes(x = STATE, y = PM25_19, fill = STATE)) +
geom_boxplot(notch = TRUE) +
ggtitle(expression(paste(PM[2.5], " Annual Concentration by New England state, 2016", sep = ""))) +
theme_minimal() +
theme(legend.position = "none") + xlab(NULL) +
ylab(expression(paste(PM[2.5]," (", mu, "g/", m^3, ")", sep = "")))
# boxplot of PM2.5 by state for 2011
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
ggplot(aes(x = STATE, y = pm_15, fill = STATE)) +
geom_boxplot(notch = TRUE) +
ggtitle(expression(paste(PM[2.5], " Annual Concentration by New England state, 2011", sep = ""))) +
theme_minimal() +
theme(legend.position = "none") + xlab(NULL) +
ylab(expression(paste(PM[2.5]," (", mu, "g/", m^3, ")", sep = "")))
# Slope graph of PM2.5 by state and region between 2011 and 2016
# Create df of 2019 actual values
PM19wSTAvgs_actual <- ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
group_by(STATE) %>%
summarize(PM25Mean = mean(PM25_19, na.rm = TRUE),
PM25wMean = weighted.mean(x = PM25_19,
w = totalpopE, na.rm = TRUE)) %>%
mutate(Year = 2016)
# Create df of 2015 values
PM15wSTAvgs_actual <- ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
group_by(STATE) %>%
summarize(PM25Mean = mean(pm_15, na.rm = TRUE),
PM25wMean = weighted.mean(x = pm_15,
w = pop_15, na.rm = TRUE)) %>%
mutate(Year = 2011)
# Create regional average benchmark
pm15NEavg <- ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
summarize(PM25Mean = mean(pm_15, na.rm = TRUE),
PM25wMean = weighted.mean(x = pm_15,
w = pop_15, na.rm = TRUE)) %>%
transmute(STATE = "NEW ENGLAND",
PM25Mean = PM25Mean,
PM25wMean = PM25wMean,
Year = 2011)
pm19NEavg <- ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
summarize(PM25Mean = mean(PM25_19, na.rm = TRUE),
PM25wMean = weighted.mean(x = PM25_19,
w = totalpopE, na.rm = TRUE)) %>%
transmute(STATE = "NEW ENGLAND",
PM25Mean = PM25Mean,
PM25wMean = PM25wMean,
Year = 2016)
#rbind tables
PM11_16wSTAvg_actual <- bind_rows(PM15wSTAvgs_actual,
PM19wSTAvgs_actual,
pm15NEavg,pm19NEavg) %>%
mutate(Year = as.factor(Year),
PM25Mean = round(PM25wMean,2),
PM25wMean = round(PM25wMean,2))
# make slope graph
newggslopegraph(dataframe = PM11_16wSTAvg_actual,
Times = Year,
Measurement = PM25Mean,
Grouping = STATE,
Title = "Annual Average PM2.5 Concentrations",
SubTitle = expression(paste
(PM[2.5]," (", mu, "g/", m^3, ")", sep = "")),
Caption = NULL,
LineColor = c("NEW ENGLAND" = "#000000",
"Connecticut" = "#E69F00",
"Massachusetts" = "#56B4E9",
"Rhode Island" = "#009E73",
"New Hampshire" = "#F0E442",
"Vermont" = "#0072B2",
"Maine" = "#D55E00"),
LineThickness = 0.7)
# SCATTER PLOTS AND CORRELATION MATRICES OF DEMO VS POLLUTION FOR NEW ENGLAND AND STATES (CORRECT FOR NON-NORMAL DISTRIBUTIONS; OR USE SPEARMAN'S RANK)
# Create a correlation matrix of PM25 and populations of concern
corrPM25 <- ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
dplyr::transmute(PM25 = PM25_19,
Minority = minority_pctE,
`Low Income` = pct2povE,
`Lang Isol` = eng_limit_pctE,
`No HS Dip` = pct_lthsE,
`Under 5` = pct_under5E,
`Over 64` = pct_over65E) %>%
drop_na() %>%
cor(method = "spearman")
corrPM25
library(ggcorrplot)
ggcorrplot(corrPM25, hc.order = TRUE, type = "lower", lab = TRUE,
title = "PM2.5 Correlation Matrix for New England, 2016",
legend.title = "Spearman's \nCorrelation\nCoefficient")
# Look at relationship of minority to PM25
# New England
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
drop_na(minority_pctE, PM25_19) %>%
ggplot(aes(x = minority_pctE, y = PM25_19)) + geom_point() +
# geom_smooth(method = "glm", formula = y~x, method.args = list(family = gaussian(link = 'log'))) +
facet_wrap("STATE")
# By state
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
drop_na(minority_pctE, PM25_19) %>%
ggplot(aes(x = minority_pctE, y = PM25_19)) + geom_point() +
facet_wrap("STATE")
# Look at relationship of low income to PM25
# New England
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
drop_na(pct2povE, PM25_19) %>%
ggplot(aes(x = pct2povE, y = PM25_19)) + geom_point()
# By state
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
drop_na(pct2povE, PM25_19) %>%
ggplot(aes(x = pct2povE, y = PM25_19)) + geom_point() +
facet_wrap("STATE")
# Look at relationship of language isolation to PM25
# New England
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
drop_na(eng_limit_pctE, PM25_19) %>%
ggplot(aes(x = eng_limit_pctE, y = PM25_19)) + geom_point(alpha = 0.3)
# By state
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
drop_na(eng_limit_pctE, PM25_19) %>%
ggplot(aes(x = eng_limit_pctE, y = PM25_19)) + geom_point(alpha = 0.3) +
facet_wrap("STATE")
# Look at relationship of less than HS education to PM25
# New England
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
drop_na(pct_lthsE, PM25_19) %>%
ggplot(aes(x = pct_lthsE, y = PM25_19)) + geom_point(alpha = 0.3) +
theme_minimal()
# By state
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
drop_na(pct_lthsE, PM25_19) %>%
ggplot(aes(x = pct_lthsE, y = PM25_19)) + geom_point(alpha = 0.3) +
facet_wrap("STATE") +
theme_minimal()
# Look at relationship of under 5 to PM25
# New England
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
drop_na(pct_under5E, PM25_19) %>%
ggplot(aes(x = pct_under5E, y = PM25_19)) + geom_point(alpha = 0.3) +
theme_minimal()
# By state
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
drop_na(pct_under5E, PM25_19) %>%
ggplot(aes(x = pct_under5E, y = PM25_19)) + geom_point(alpha = 0.3) +
facet_wrap("STATE") +
theme_minimal()
# Look at relationship of over 64 to PM25
# New England
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
drop_na(pct_over65E, PM25_19) %>%
ggplot(aes(x = pct_over65E, y = PM25_19)) + geom_point(alpha = 0.3) +
theme_minimal()
# By state
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
drop_na(pct_over65E, PM25_19) %>%
ggplot(aes(x = pct_over65E, y = PM25_19)) + geom_point(alpha = 0.3) +
facet_wrap("STATE") +
theme_minimal()
# POP WEIGHTED AVGS FOR POLLUTION FOR NEW ENGLAND AND STATES, INCLUDING EJ INDICES
# Pop Weighted avg of PM2.5 for all Groups in New England relative to NE average
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
# filter(STATE == "Massachusetts") %>%
dplyr::select(totalpopE,
nhwhitepopE,
minorityE,
nhblackpopE,
nhamerindpopE,
nhasianpopE,
nhnativhpopE,
nhotherpopE,
nh2morepopE,
hisppopE,
povknownE,
num2povE,
eng_hhE,
eng_limitE,
age25upE,
lthsE,
allAgesE,
under5E,
over65E,
PM25_19) %>%
gather(key = Group, value = Pop, totalpopE:over65E) %>%
group_by(Group) %>%
summarize(PM25wMean = weighted.mean(x = PM25_19, w = Pop, na.rm = TRUE),
PM25Mean = mean(PM25_19, na.rm = TRUE)) %>%
spread(key = Group, value = PM25wMean) %>%
transmute(Minority = (minorityE/PM25Mean - 1)*100,
#Minority_NHW = (minorityE/nhwhitepopE - 1)*100,
`Lang Isol` = (eng_limitE/PM25Mean - 1)*100,
Poverty = (num2povE/PM25Mean - 1)*100,
`No HS` = (lthsE/PM25Mean - 1)*100,
`Under 5` = (under5E/PM25Mean - 1)*100,
`Over 65` = (over65E/PM25Mean - 1)*100) %>%
gather(key = Group, value = Pct) %>%
ggplot(aes(x = reorder(Group, -Pct), y = Pct, fill = Group)) +
geom_bar(stat = "identity", position = "identity") +
theme_minimal() +
labs(x = "", y = "", title = expression(paste("Population-Weighted ", PM[2.5], " Exposure (relative to New England average)"))) +
theme(legend.position = 'none') +
geom_text(aes(x = Group, y = Pct + 0.2 * sign(Pct),
label = paste0(round(Pct,2),"%")),
hjust = 0.5, size = 3,
color=rgb(100,100,100, maxColorValue=255)) +
scale_y_continuous(labels = function(x) paste0(x, "%")) +
geom_hline(yintercept = 0)
# Pop Weighted avg of PM2.5 EXPOSURE CHANGE 2011 - 2016 for all Groups in New England relative to NE average. NOTE THAT ALL BLOCK GROUPS SHOWED NEGATIVE CHANGE (i.e. DECLINE), MEANING PM10 WENT DOWN. SINCE NUMERATOR AND DENOMINATORS ARE NEGATIVE, PERCENT CHANGE MEANS DECREASE RELATIVE TO AVERAGE. NEGATIVE VALUES INDICATE SLOWER DECLINE THAN AVERAGE; POSITIVE NUMBERS MEAN FASTER DECLINE THAN AVERAGE.
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
# filter(STATE == "Massachusetts") %>%
dplyr::select(totalpopE,
nhwhitepopE,
minorityE,
nhblackpopE,
nhamerindpopE,
nhasianpopE,
nhnativhpopE,
nhotherpopE,
nh2morepopE,
hisppopE,
povknownE,
num2povE,
eng_hhE,
eng_limitE,
age25upE,
lthsE,
allAgesE,
under5E,
over65E,
PM25_pctChange) %>%
gather(key = Group, value = Pop, totalpopE:over65E) %>%
group_by(Group) %>%
summarize(PM25wMean = weighted.mean(x = PM25_pctChange,
w = Pop, na.rm = TRUE),
PM25Mean = mean(PM25_pctChange, na.rm = TRUE)) %>%
spread(key = Group, value = PM25wMean) %>%
transmute(Minority = (minorityE/PM25Mean - 1)*100,
#Minority_NHW = (minorityE/nhwhitepopE - 1)*100,
`Lang Isol` = (eng_limitE/PM25Mean - 1)*100,
Poverty = (num2povE/PM25Mean - 1)*100,
`No HS` = (lthsE/PM25Mean - 1)*100,
`Under 5` = (under5E/PM25Mean - 1)*100,
`Over 65` = (over65E/PM25Mean - 1)*100) %>%
gather(key = Group, value = Pct) %>%
ggplot(aes(x = reorder(Group, -Pct), y = Pct, fill = Group)) +
geom_bar(stat = "identity", position = "identity") +
theme_minimal() +
labs(x = "", y = "", title = expression(atop(paste("Population-Weighted ", PM[2.5], " Exposure CHANGE 2011 - 2016"), " (relative to New England average)"))) +
theme(legend.position = 'none') +
geom_text(aes(x = Group, y = Pct + 0.2 * sign(Pct),
label = paste0(round(Pct,2),"%")),
hjust = 0.5, size = 3,
color=rgb(100,100,100, maxColorValue=255)) +
scale_y_continuous(labels = function(x) paste0(x, "%")) +
geom_hline(yintercept = 0)
# Slope graph of change in pop-weighted PM2.5 exposure beteween 2011 and 2016
# Create df of 2019 values
PM19wAvgs <- ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
# filter(STATE == "Massachusetts") %>%
dplyr::select(totalpopE,
nhwhitepopE,
minorityE,
nhblackpopE,
nhamerindpopE,
nhasianpopE,
nhnativhpopE,
nhotherpopE,
nh2morepopE,
hisppopE,
povknownE,
num2povE,
eng_hhE,
eng_limitE,
age25upE,
lthsE,
allAgesE,
under5E,
over65E,
PM25_19) %>%
gather(key = Group, value = Pop, totalpopE:over65E) %>%
group_by(Group) %>%
summarize(PM25wMean = weighted.mean(x = PM25_19,
w = Pop, na.rm = TRUE),
PM25Mean = mean(PM25_19, na.rm = TRUE)) %>%
spread(key = Group, value = PM25wMean) %>%
transmute(Minority = (minorityE/PM25Mean - 1)*100,
#Minority_NHW = (minorityE/nhwhitepopE - 1)*100,
`Lang Isol` = (eng_limitE/PM25Mean - 1)*100,
Poverty = (num2povE/PM25Mean - 1)*100,
`No HS` = (lthsE/PM25Mean - 1)*100,
`Under 5` = (under5E/PM25Mean - 1)*100,
`Over 65` = (over65E/PM25Mean - 1)*100) %>%
gather(key = Group, value = Pct) %>%
mutate(Year = 2016)
# Create df of 2015 values
PM15wAvgs <- ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
# filter(STATE == "Massachusetts") %>%
dplyr::select(pop_15,
mins_15,
lowinc_15,
lingiso_15,
lths_15,
under5_15,
over64_15,
pm_15) %>%
gather(key = Group, value = Pop, pop_15:over64_15) %>%
group_by(Group) %>%
summarize(PM25wMean = weighted.mean(x = pm_15,
w = Pop, na.rm = TRUE),
PM25Mean = mean(pm_15, na.rm = TRUE)) %>%
spread(key = Group, value = PM25wMean) %>%
transmute(Minority = (mins_15/PM25Mean - 1)*100,
#Minority_NHW = (minorityE/nhwhitepopE - 1)*100,
`Lang Isol` = (lingiso_15/PM25Mean - 1)*100,
Poverty = (lowinc_15/PM25Mean - 1)*100,
`No HS` = (lths_15/PM25Mean - 1)*100,
`Under 5` = (under5_15/PM25Mean - 1)*100,
`Over 65` = (over64_15/PM25Mean - 1)*100) %>%
gather(key = Group, value = Pct) %>%
mutate(Year = 2011)
# Create regional average benchmark
pmRegionalAvg <- data.frame(
Group = c("REGIONAL AVG", "REGIONAL AVG"),
Pct = c(0,0),
Year = c(2011,2016)
)
#rbind tables
PM11_16wAvg <- bind_rows(PM15wAvgs,PM19wAvgs,pmRegionalAvg) %>%
mutate(Year = as.factor(Year),
Pct = round(Pct,2))
# make slope graph
newggslopegraph(dataframe = PM11_16wAvg,
Times = Year,
Measurement = Pct,
Grouping = Group,
Title = "Population-Weighted PM2.5 Exposure",
SubTitle = "Relative to New England Average",
Caption = "Values represent percentage of regional average PM2.5 levels. Positive values \nindicate exposure for those groups are higher than the regional average; negative \nvalues indicate exposure for those groups are less than the regional average.",
LineColor = c("REGIONAL AVG" = "#000000",
"Lang Isol" = "#E69F00",
"Minority" = "#56B4E9",
"No HS" = "#009E73",
"Poverty" = "#F0E442",
"Under 5" = "#0072B2",
"Over 65" = "#D55E00"))
# Create df of 2019 actual values
PM19wAvgs_actual <- ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
# filter(STATE == "Massachusetts") %>%
dplyr::select(minorityE,
num2povE,
eng_limitE,
lthsE,
under5E,
over65E,
PM25_19) %>%
gather(key = Group, value = Pop, minorityE:over65E) %>%
group_by(Group) %>%
summarize(PM25wMean = weighted.mean(x = PM25_19,
w = Pop, na.rm = TRUE)) %>%
mutate(Group = case_when(
Group == "minorityE" ~ "Minority",
Group == "eng_limitE" ~ "Lang Isol",
Group == "num2povE" ~ "Poverty",
Group == "lthsE" ~ "No HS",
Group == "under5E" ~ "Under 5",
Group == "over65E" ~ "Over 65")) %>%
mutate(Year = 2016)
# Create df of 2015 values
PM15wAvgs_actual <- ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
# filter(STATE == "Massachusetts") %>%
dplyr::select(mins_15,
lowinc_15,
lingiso_15,
lths_15,
under5_15,
over64_15,
pm_15) %>%
gather(key = Group, value = Pop, mins_15:over64_15) %>%
group_by(Group) %>%
summarize(PM25wMean = weighted.mean(x = pm_15,
w = Pop, na.rm = TRUE)) %>%
mutate(Group = case_when(
Group == "mins_15" ~ "Minority",
Group == "lingiso_15" ~ "Lang Isol",
Group == "lowinc_15" ~ "Poverty",
Group == "lths_15" ~ "No HS",
Group == "under5_15" ~ "Under 5",
Group == "over64_15" ~ "Over 65")) %>%
mutate(Year = 2011)
# Create regional average benchmark
pm15NEavg <- mean(ne_blkgrp_sf_DemoEJ$pm_15, na.rm = TRUE)
pm19NEavg <- mean(ne_blkgrp_sf_DemoEJ$PM25_19, na.rm = TRUE)
pmRegionalAvg_actual <- data.frame(
Group = c("REGIONAL AVG", "REGIONAL AVG"),
PM25wMean = c(pm15NEavg,pm19NEavg),
Year = c(2011,2016)
)
#rbind tables
PM11_16wAvg_actual <- bind_rows(PM15wAvgs_actual,
PM19wAvgs_actual,
pmRegionalAvg_actual) %>%
mutate(Year = as.factor(Year),
PM25wMean = round(PM25wMean,1))
# make slope graph
newggslopegraph(dataframe = PM11_16wAvg_actual,
Times = Year,
Measurement = PM25wMean,
Grouping = Group,
Title = "Population-Weighted PM2.5 Exposure",
SubTitle = "in micrograms per cubic meter",
Caption = NULL,
LineColor = c("REGIONAL AVG" = "#000000",
"Lang Isol" = "#E69F00",
"Minority" = "#56B4E9",
"No HS" = "#009E73",
"Poverty" = "#F0E442",
"Under 5" = "#0072B2",
"Over 65" = "#D55E00"))
# Pop Weighted avg of PM2.5 for ALL GROUPS in New England relative to CONTRAST GROUPS
ne_blkgrp_sf_DemoEJ %>%
as.data.frame() %>%
# filter(STATE == "Massachusetts") %>%
dplyr::select(totalpopE,
nhwhitepopE,
minorityE,
nhblackpopE,
nhamerindpopE,
nhasianpopE,
nhnativhpopE,
nhotherpopE,
nh2morepopE,
hisppopE,
povknownE,
num2povE,
eng_hhE,