-
Notifications
You must be signed in to change notification settings - Fork 0
/
Evacuation_NewEngland.R
1403 lines (1273 loc) · 55.9 KB
/
Evacuation_NewEngland.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
# Evacuation risks analysis. Identify the number of people within areas that are at risk of flooding and thus potentially need evacuation in the event of an emergency.
library(tidyverse)
library(sf)
library(tmap)
library(tmaptools)
library(lwgeom)
library(tigris)
options(tigris_use_cache = TRUE, tigris_class = "sf")
# library(raster)
# library(fasterize)
load("DATA/ne_layers.rds")
# Download Census TIGERLine hydrography for RI
## First, extract list of county names to use with tigris::water
ri_counties <- counties("RI") %>%
pull(NAME)
# Next, download water features for each county and rbind to one layer
ri_awater_sf <- rbind_tigris(
lapply(
ri_counties, function(x) area_water(state = "RI", county = x)
)
) %>%
st_union() %>%
st_as_sf() %>%
st_transform(., crs = 2840)
# Download linear water features for each county and rbind to one layer
ri_lwater_sf <- rbind_tigris(
lapply(
ri_counties, function(x) linear_water(state = "RI", county = x)
)
) %>%
st_union() %>%
st_as_sf()
# Read in conservation areas to eliminate unpopulated from areal interpolation. See http://www.rigis.org/datasets/local-conservation-areas
ri_localCon_sf <- st_read(dsn = "DATA/FEMA/RI",
layer = "Local_Conservation_Areas") %>%
st_transform(., crs = 2840) %>%
st_union() %>%
st_as_sf() %>%
st_make_valid()
ri_stateCon_sf <- st_read(dsn = "DATA/FEMA/RI",
layer = "State_Conservation_Areas") %>%
st_transform(., crs = 2840) %>%
st_union() %>%
st_as_sf() %>%
st_make_valid()
# Create point layer of major cities for context
# Note cb=FALSE is necessary for extracting centroids from town polygons. Otherwise, if cb=TRUE, cannot extract centroids from multipolygon features.
ri_towns_sf_pts <- county_subdivisions(state = "RI", cb = TRUE) %>%
filter(NAME %in% c("Providence",
"Woonsocket",
"Pawtucket",
"Warwick",
"Bristol",
"Portsmouth",
"Newport",
"Narragansett",
"North Kingstown",
"Charlestown",
"Situate",
"Glocester")) %>%
st_transform(., crs = 2840) %>%
st_centroid(of_largest_polygon = TRUE)
# Create road layer for context
ri_highways <- primary_roads() %>%
filter(FULLNAME %in% c("I- 95","I- 195","I- 295", "US Hwy 6")) %>%
# group_by(FULLNAME) %>%
# summarize(RTTYP = unique(RTTYP),
# MTFCC = unique(MTFCC)) %>%
tmaptools::crop_shape(., ne_states_sf_cb) %>%
st_transform(., crs = 2840)
# Extract highway segments for labeling
I95roadSegment <- ri_highways %>%
filter(LINEARID == "110468245978")
I95roadSegment2 <- ri_highways %>%
filter(LINEARID == "1107052605232")
I295roadSegment <- ri_highways %>%
filter(LINEARID == "1104755623349")
I195roadSegment <- ri_highways %>%
filter(LINEARID == "110448466166")
# Create custom icons of highway shields
I95 <- tmap_icons(file = "https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/I-95.svg/200px-I-95.svg.png")
I195 <- tmap_icons("https://upload.wikimedia.org/wikipedia/commons/thumb/f/f7/I-195.svg/200px-I-195.svg.png")
I295 <- tmap_icons("https://upload.wikimedia.org/wikipedia/commons/thumb/4/41/I-295.svg/200px-I-295.svg.png")
# Read in NFHL for RI. Data comes from FEMA.
# List available layers in geodatabase
# st_layers("DATA/FEMA/RI/NFHL_44_20181118.gdb")
# Read in flood hazard areas
ri_fhza_2840 <- st_read(dsn = "DATA/FEMA/RI/NFHL_44_20181118.gdb",
layer = "S_Fld_Haz_Ar") %>%
filter(FLD_ZONE != "OPEN WATER" &
!ZONE_SUBTY %in% c("AREA OF MINIMAL FLOOD HAZARD",
"AREA WITH REDUCED FLOOD RISK DUE TO LEVEE")) %>%
mutate(FLD_ZONE = as.character(FLD_ZONE)) %>% # omit unused factor levels
st_transform(., crs = 2840) %>%
st_make_valid() %>%
group_by(FLD_ZONE) %>% # aggregate flood zone polygons
summarize(count = n()) %>%
mutate(Area = st_area(.),
Interval = case_when(
FLD_ZONE == "A" ~ "100-year",
FLD_ZONE == "AE" ~ "100-year",
FLD_ZONE == "AH" ~ "100-year",
FLD_ZONE == "AO" ~ "100-year",
FLD_ZONE == "VE" ~ "100-year",
FLD_ZONE == "X" ~ "500-year"))
# crop flood zones to land areas only
ri_state_sf <- ne_states_sf_cb %>%
filter(NAME == "Rhode Island")
ri_fhza_2840_land <- ri_fhza_2840 %>%
crop_shape(., ri_state_sf, polygon = TRUE) %>%
st_difference(., ri_awater_sf) %>%
mutate(Area = st_area(.))
# Total land area of RI within flood zones
ri_fhza_2840_land %>%
as.data.frame() %>%
group_by(Interval) %>%
summarize(SqKm = round(as.numeric(sum(Area)/10^6),1),
SqMi = round(as.numeric(SqKm/2.59),1))
# Percentage of RI land within flood zones
round(as.numeric(sum(ri_fhza_2840_land$Area)/ri_state_sf$ALAND)*100,1)
# map out flood hazard areas
tmap_mode("view")
tm_shape(ri_awater_sf) + tm_fill(col = "skyblue", alpha = 0.4) +
tm_shape(ri_fhza_2840_land) + tm_fill(col = "FLD_ZONE", alpha = 0.7) +
tm_shape(ri_state_sf) + tm_borders()
# read in hurricane evacuation zone layer
ri_hea_sf <- st_read(dsn = "DATA/FEMA/RI",
layer = "Hurricane_Evacuation_Areas") %>%
mutate(EVAC = as.character(EVAC)) %>%
filter(EVAC %in% c("A","B","C")) %>%
st_transform(., crs = 2840) %>%
st_make_valid() %>%
mutate(Area = st_area(.))
# Total land area with hurricane evacuation zones
ri_hea_sf %>%
as.data.frame() %>%
group_by(EVAC) %>%
summarize(SqKm = round(as.numeric(sum(Area)/10^6),1),
SqMi = round(as.numeric(SqKm/2.59),1))
# Percentage of area within evac zones
round(as.numeric(sum(ri_hea_sf$Area)/ri_state_sf$ALAND)*100,1)
# map out hurricane evacuation zones
tm_shape(ri_hea_sf) + tm_fill(col = "EVAC", alpha = 0.7)
# # Map out high and moderate risk flood zones
# RI_FHZA %>%
# filter(FLD_ZONE != "OPEN WATER" &
# !ZONE_SUBTY %in% c("AREA OF MINIMAL FLOOD HAZARD",
# "AREA WITH REDUCED FLOOD RISK DUE TO LEVEE")) %>%
# mutate(FLD_ZONE = as.character(FLD_ZONE)) %>% # omit unused factor levels
# tm_shape(.) + tm_fill("FLD_ZONE") +
# tm_shape(ne_states_sf_cb) + tm_borders()
#
# # Map out moderate risk flood zones
# RI_FHZA %>%
# filter(ZONE_SUBTY %in% c("0.2 PCT ANNUAL CHANCE FLOOD HAZARD","FLOODWAY")) %>%
# mutate(FLD_ZONE = as.character(FLD_ZONE)) %>% # omit unused factor levels
# tm_shape(.) + tm_fill("FLD_ZONE", palette = c(AE = "blue", X = "red")) +
# tm_shape(ne_states_sf_cb) + tm_borders()
#
# # Map out minimal risk flood zones
# RI_FHZA %>%
# filter(ZONE_SUBTY == "AREA OF MINIMAL FLOOD HAZARD") %>%
# mutate(FLD_ZONE = as.character(FLD_ZONE)) %>% # omit unused factor levels
# tm_shape(.) + tm_fill("FLD_ZONE") +
# tm_shape(ne_states_sf_cb) + tm_borders()
# Use areal interpolation to calculate populations within flood zones. Approach follows method used by Qiang (2019) to eliminate unpopulated areas and then downscale populations to raster pixels.
# Convert to projected local CRS EPSG:2840: NAD83(HARN) / Rhode Island
ri_blkgrp_2840 <- ne_blkgrp_sf %>%
filter(STATE == "Rhode Island") %>%
st_transform(., crs = 2840)
ri_tracts_2840 <- ne_tracts_sf %>%
filter(STATE == "Rhode Island") %>%
st_transform(., crs = 2840)
# Get rid of empty geometries
empty_geo <- st_is_empty(ri_fhza_2840)
ri_fhza_2840 <- ri_fhza_2840[!empty_geo,]
empty_geo <- st_is_empty(ri_blkgrp_2840)
ri_blkgrp_2840 <- ri_blkgrp_2840[!empty_geo,]
empty_geo <- st_is_empty(ri_tracts_2840)
ri_tracts_2840 <- ri_tracts_2840[!empty_geo,]
# Filter out block group areas overlapping with water or conservation areas so that we do not count exposed populations in areas where there are unlikely to be residents
start_time <- Sys.time()
ri_blkrps_fix <- st_difference(ri_blkgrp_2840,ri_awater_sf) %>%
st_difference(., ri_localCon_sf) %>%
st_difference(., ri_stateCon_sf)
end_time <- Sys.time()
end_time - start_time # takes about 7.5 - 9.5 mins
# repeat for tracts
start_time <- Sys.time()
ri_tracts_fix <- st_difference(ri_tracts_2840,ri_awater_sf) %>%
st_difference(., ri_localCon_sf) %>%
st_difference(., ri_stateCon_sf)
end_time <- Sys.time()
end_time - start_time # takes about 7.75 - 8.5 mins
# # Save layers since it takes a long time to run
# save(ri_blkrps_fix, ri_tracts_fix, file = "DATA/FEMA/RI/ri_fix.rds")
# read in National Land Cover Database raster data
nlcd <- raster("DATA/NLCD_2016_Land_Cover_L48_20190424.img")
# create polygon layer in same crs as raster to crop
ri_polys <- st_transform(ri_blkgrp_2840, crs = projection(nlcd))
# create a function to reclassify NLCD pixels that are not 'developed' as NA
rc <- function(x) {
ifelse(x >= 21 & x <= 24, 1, NA)
}
# Define the Proj.4 spatial reference
# http://spatialreference.org/ref/epsg/2840/proj4/
newCRS <- "+proj=tmerc +lat_0=41.08333333333334 +lon_0=-71.5 +k=0.99999375 +x_0=100000 +y_0=0 +ellps=GRS80 +units=m +no_defs"
# crop raster to region and reproject to RI state plane
start_time <- Sys.time()
ri_nlcd_2840 <- crop(nlcd, ri_polys) %>%
calc(., fun=rc) %>%
projectRaster(., crs = newCRS)
end_time <- Sys.time()
end_time - start_time
# count number of developed NLCD cells per block group and calc pop per cell. Once we know the pop per pixel we can count the number of pixels falling within the flood zone to get the exposed population.
start_time <- Sys.time()
ri_blkgrp_cnt <- ri_blkrps_fix %>%
mutate(RI_LOWINC = if_else(RI_INCOME == "I",totalpopE,0)) %>%
mutate(RI_LOWINC = replace_na(RI_LOWINC,0)) %>%
mutate(RI_MINORITIES = if_else(RI_MINORITY == "M", totalpopE,0)) %>%
mutate(RI_MINORITIES = replace_na(RI_MINORITIES,0)) %>%
dplyr::select(GEOID,
totalpopE,
minorityE,
under5E,
over64E,
under18E,
eng_limitE,
num2povE,
lthsE,
RI_LOWINC,
RI_MINORITIES) %>%
as_Spatial() %>%
raster::extract(ri_nlcd_2840, .,
fun = function(x, ...) length(na.omit(x)),
sp=TRUE, na.rm=TRUE, small=TRUE) %>%
st_as_sf() %>%
rename(cells = layer) %>%
mutate(popCell = totalpopE/cells,
minorityCell = minorityE/cells,
under5Cell = under5E/cells,
over64Cell = over64E/cells,
under18Cell = under18E/cells,
engLimitCell = eng_limitE/cells,
num2povCell = num2povE/cells,
lthsCell = lthsE/cells,
RIlowIncCell = RI_LOWINC/cells,
RIminorityCell = RI_MINORITIES/cells)
end_time <- Sys.time()
end_time - start_time # takes about 2.5 - 3.4 mins
# repeat for tracts
start_time <- Sys.time()
ri_tract_cnt <- ri_tracts_fix %>%
dplyr::select(GEOID,
disabledOver18E,
HHnoCarE) %>%
as_Spatial() %>%
raster::extract(ri_nlcd_2840, .,
fun = function(x, ...) length(na.omit(x)),
sp=TRUE, na.rm=TRUE, small=TRUE) %>%
st_as_sf() %>%
rename(cells = layer) %>%
mutate(disabledCell = disabledOver18E/cells,
HHnoCarCell = HHnoCarE/cells)
end_time <- Sys.time()
end_time - start_time # takes about 3 mins
# # convert block group polygons to raster and mask out NA values
# start_time <- Sys.time()
# ri_blkgrp_ras <- fasterize(sf = ri_blkgrp_cnt, raster = ri_nlcd_2840,
# field = "popCell", fun = "first") %>%
# mask(., ri_nlcd_2840)
# end_time <- Sys.time()
# end_time - start_time
# Convert block groups to raster with pop per pixel as value
# iterate through variables in ri_blkgrp_cnt and create raster for each
# create a vector of variable names over which to iterate
fields <- names(as.data.frame(ri_blkgrp_cnt)[14:23])
fields_tracts <- names(as.data.frame(ri_tract_cnt)[6:7])
ri_blkgrp_ras_list <- lapply(fields, FUN = function(x) {
fasterize(sf = ri_blkgrp_cnt, raster = ri_nlcd_2840,
field = x, fun = "first") %>%
mask(., ri_nlcd_2840)
})
ri_tracts_ras_list <- lapply(fields_tracts, FUN = function(x) {
fasterize(sf = ri_tract_cnt, raster = ri_nlcd_2840,
field = x, fun = "first") %>%
mask(., ri_nlcd_2840)
})
# assign names to list elements
names(ri_blkgrp_ras_list) <- fields
names(ri_tracts_ras_list) <- fields_tracts
# map it out
tmap_mode("view")
ri_blkgrp_ras_list[[1]] %>%
tm_shape(.) + tm_raster(alpha = 0.7) +
tm_shape(RI_FHZA_2840) + tm_borders(col = "blue")
tmap_mode("view")
ri_tracts_ras_list[[1]] %>%
tm_shape(.) + tm_raster(alpha = 0.7) +
tm_shape(RI_FHZA_2840) + tm_borders(col = "blue")
# # remove last item in list because it's just the geometry column
# ri_blkgrp_ras_list[length(ri_blkgrp_ras_list)] <- NULL
# # extract sum of population within flood zones
# start_time <- Sys.time()
# ri_fhza_pop <- RI_FHZA_2840 %>%
# as_Spatial() %>%
# extract(ri_blkgrp_ras, ., fun = sum,
# sp = TRUE, na.rm = TRUE, small = TRUE) %>%
# st_as_sf() %>%
# mutate(pop = layer)
# end_time <- Sys.time()
# end_time - start_time
# iterate through list and extract sum of pops within flood zone
start_time <- Sys.time()
ri_blkgrp_flood_list <- lapply(ri_blkgrp_ras_list, function(x) {
RI_FHZA_2840 %>%
as_Spatial() %>%
extract(x, ., fun = sum,
sp = TRUE, na.rm = TRUE, small = TRUE) %>%
st_as_sf()
})
end_time <- Sys.time()
end_time - start_time # takes about 46 - 51 mins
# iterate through list and extract sum of pops within hurricane evacuation zones
start_time <- Sys.time()
ri_blkgrp_hevac_list <- lapply(ri_blkgrp_ras_list, function(x) {
ri_hea_sf %>%
as_Spatial() %>%
raster::extract(x, ., fun = sum,
sp = TRUE, na.rm = TRUE, small = TRUE) %>%
st_as_sf()
})
end_time <- Sys.time()
end_time - start_time # takes about 22 mins
# repeat for tracts
start_time <- Sys.time()
ri_tracts_flood_list <- lapply(ri_tracts_ras_list, function(x) {
RI_FHZA_2840 %>%
as_Spatial() %>%
raster::extract(x, ., fun = sum,
sp = TRUE, na.rm = TRUE, small = TRUE) %>%
st_as_sf()
})
end_time <- Sys.time()
end_time - start_time # takes about 10 mins
# repeat for tracts for hurricane evacuation zones
start_time <- Sys.time()
ri_tracts_hevac_list <- lapply(ri_tracts_ras_list, function(x) {
ri_hea_sf %>%
as_Spatial() %>%
raster::extract(x, ., fun = sum,
sp = TRUE, na.rm = TRUE, small = TRUE) %>%
st_as_sf()
})
end_time <- Sys.time()
end_time - start_time # takes about 4.5 mins
# save a copy jic
# save(ri_blkgrp_flood_list,ri_tracts_flood_list, ri_tracts_hevac_list, ri_blkgrp_hevac_list, file = "DATA/FEMA/RI/ri_flood_lists.rds")
# class(ri_blkgrp_flood_list[[1]])
# names(ri_blkgrp_flood_list)
# glimpse(as.data.frame(ri_blkgrp_flood_list[[1]]))
# # Sum of population within flood zones
# as.data.frame(ri_blkgrp_flood_list[[2]]) %>%
# summarize(sum(layer))
# # map it out
# tmap_mode("view")
# ri_blkgrp_flood_list[[1]] %>%
# tm_shape(.) + tm_fill("layer", alpha = 0.5)
# create a df of sum of flooded pops for each group
# first, convert each list item from sf to df
ri_flooded_df <- lapply(ri_blkgrp_flood_list, FUN = as.data.frame) %>%
# next, extract layer column from each list df.
lapply(., "[", "layer") %>%
# finally, append columns to one df
do.call(cbind, .)
# name the columns and replace Cell with BG
names(ri_flooded_df) <- str_replace(fields, "Cell", "BG")
# Add the flood zone column
ri_flooded_df <- ri_blkgrp_flood_list[[1]] %>%
as.data.frame() %>%
dplyr::select(FLD_ZONE) %>%
cbind(., ri_flooded_df)
# do the same for hurricane evac data for block groups
# first, convert each list item from sf to df
ri_blkgrp_hevac_df <- lapply(ri_blkgrp_hevac_list, FUN = as.data.frame) %>%
# next, extract layer column from each list df.
lapply(., "[", "layer") %>%
# finally, append columns to one df
do.call(cbind, .)
# name the columns and replace Cell with BG
names(ri_blkgrp_hevac_df) <- str_replace(fields, "Cell", "BG")
# Add the hurricane evac zone column
ri_blkgrp_hevac_df <- ri_blkgrp_hevac_list[[1]] %>%
as.data.frame() %>%
dplyr::select(EVAC) %>%
cbind(., ri_blkgrp_hevac_df)
# repeat for tracts
ri_floodedTracts_df <- lapply(ri_tracts_flood_list, FUN = as.data.frame) %>%
lapply(., "[", "layer") %>%
do.call(cbind, .)
# name the columns and replace Cell with BG
names(ri_floodedTracts_df) <- str_replace(fields_tracts, "Cell", "CT")
# Add the flood zone column
ri_floodedTracts_df <- ri_tracts_flood_list[[1]] %>%
as.data.frame() %>%
dplyr::select(FLD_ZONE) %>%
cbind(., ri_floodedTracts_df)
# do the same for hurricane evac data for tracts
ri_tracts_hevac_df <- lapply(ri_tracts_hevac_list, FUN = as.data.frame) %>%
lapply(., "[", "layer") %>%
do.call(cbind, .)
# name the columns and replace Cell with BG
names(ri_tracts_hevac_df) <- str_replace(fields_tracts, "Cell", "CT")
# Add the hurricane evac zone column
ri_tracts_hevac_df <- ri_tracts_hevac_list[[1]] %>%
as.data.frame() %>%
dplyr::select(EVAC) %>%
cbind(., ri_tracts_hevac_df)
# Sum total block group populations within flood zones
ri_bgsum_flooded <- ri_flooded_df %>%
dplyr::select(-FLD_ZONE) %>%
rename(`Total Pop` = popBG,
Minority = minorityBG,
`Under 5` = under5BG,
`Over 64` = over64BG,
`Under 18` = under18BG,
`Limited English HH` = engLimitBG,
`Low Income` = num2povBG,
`No HS Dip` = lthsBG,
`RI Low Income` = RIlowIncBG,
`RI Minority` = RIminorityBG) %>%
gather(key = "Group", value = "FloodPop") %>%
group_by(Group) %>%
summarize(FloodPop = sum(FloodPop, na.rm = TRUE))
# Sum block group populations of concern for the state
ri_blkgrp_sum <- ri_blkgrp_2840 %>%
as.data.frame() %>%
mutate(RI_LOWINC = if_else(RI_INCOME == "I",totalpopE,0)) %>%
mutate(RI_LOWINC = replace_na(RI_LOWINC,0)) %>%
mutate(RI_MINORITIES = if_else(RI_MINORITY == "M", totalpopE,0)) %>%
mutate(RI_MINORITIES = replace_na(RI_MINORITIES,0)) %>%
transmute(`Total Pop` = totalpopE,
Minority = minorityE,
`Under 5` = under5E,
`Over 64` = over64E,
`Under 18` = under18E,
`Limited English HH` = eng_limitE,
`Low Income` = num2povE,
`No HS Dip` = lthsE,
`RI Low Income` = RI_LOWINC,
`RI Minority` = RI_MINORITIES) %>%
gather(., key = "Group", value = "RIPop") %>%
group_by(Group) %>%
summarize(RIPop = sum(RIPop, na.rm = TRUE))
# Sum total block group populations within hurricane evacuation zones
ri_bgsum_hevac <- ri_blkgrp_hevac_df %>%
dplyr::select(-EVAC) %>%
rename(`Total Pop` = popBG,
Minority = minorityBG,
`Under 5` = under5BG,
`Over 64` = over64BG,
`Under 18` = under18BG,
`Limited English HH` = engLimitBG,
`Low Income` = num2povBG,
`No HS Dip` = lthsBG,
`RI Low Income` = RIlowIncBG,
`RI Minority` = RIminorityBG) %>%
gather(key = "Group", value = "HevacPop") %>%
group_by(Group) %>%
summarize(HevacPop = sum(HevacPop, na.rm = TRUE))
# repeat for tracts
# Sum total tract populations within flood zones
ri_ctsum_flooded <- ri_floodedTracts_df %>%
dplyr::select(-FLD_ZONE) %>%
rename(Disabled = disabledCT,
`No Car HH` = HHnoCarCT) %>%
gather(key = "Group", value = "FloodPop") %>%
group_by(Group) %>%
summarize(FloodPop = sum(FloodPop, na.rm = TRUE))
# Sum tract populations of concern for the state
ri_tracts_sum <- ri_tracts_2840 %>%
as.data.frame() %>%
transmute(Disabled = disabledOver18E,
`No Car HH` = HHnoCarE) %>%
gather(., key = "Group", value = "RIPop") %>%
group_by(Group) %>%
summarize(RIPop = sum(RIPop, na.rm = TRUE))
# Sum total tract populations within hurricane evacuation zones
ri_ctsum_hevac <- ri_tracts_hevac_df %>%
dplyr::select(-EVAC) %>%
rename(Disabled = disabledCT,
`No Car HH` = HHnoCarCT) %>%
gather(key = "Group", value = "HevacPop") %>%
group_by(Group) %>%
summarize(HevacPop = sum(HevacPop, na.rm = TRUE))
# join tract flooded and state pops together
ri_tract_join <- left_join(ri_tracts_sum,ri_ctsum_flooded,by="Group") %>%
left_join(., ri_ctsum_hevac,by="Group")
# Bring df to together and calculate percentge of population groups within flood zones and hurricane evacuation zones
ri_flooded <- left_join(ri_blkgrp_sum, ri_bgsum_flooded, by = "Group") %>%
left_join(., ri_bgsum_hevac, by = "Group") %>%
rbind(., ri_tract_join) %>%
mutate(PctFlooded = FloodPop/RIPop*100,
PctHevac = HevacPop/RIPop*100)
# save for later
save(ri_flooded, file = "DATA/FEMA/RI/ri_flooded.rds")
# Create table in descending order by flooded pop
arrange(ri_flooded,desc(FloodPop))
# Create lollipop plot of flood exposed populations
ri_flooded %>%
ggplot(aes(x = reorder(Group,-PctFlooded),
y = PctFlooded)) +
geom_segment(aes(x = reorder(Group,-PctFlooded),
xend = reorder(Group,-PctFlooded),
y = pull(ri_flooded[8,5]), yend = PctFlooded),
color = "skyblue") +
geom_point(color = "blue", size = 4, alpha = 0.8) +
coord_flip() + xlab("") + ylab("") + ggtitle("Rhode Island Populations within Flood Zones") + theme_light() +
theme(panel.grid.major.y = element_blank(),
panel.border = element_blank(),
axis.ticks.y = element_blank()) +
geom_text(aes(x = Group, y = PctFlooded + 0.2 * sign(PctFlooded),
label = paste0(round(PctFlooded,1),"%")),
hjust = 0.1, vjust = -0.5, size = 3,
color=rgb(100,100,100, maxColorValue=255)) +
scale_y_continuous(labels = function(x) paste0(x, "%")) +
geom_hline(yintercept = pull(ri_flooded[8,5]), linetype = "dashed")
# Create lollipop plot of populations within hurricane evacuation zones
ri_flooded %>%
ggplot(aes(x = reorder(Group,-PctHevac),
y = PctHevac)) +
geom_segment(aes(x = reorder(Group,-PctHevac),
xend = reorder(Group,-PctHevac),
y = pull(ri_flooded[8,6]), yend = PctHevac),
color = "skyblue") +
geom_point(color = "blue", size = 4, alpha = 0.8) +
coord_flip() + xlab("") + ylab("") + ggtitle("Rhode Island Populations within Hurricane Evacuation Zones") + theme_light() +
theme(panel.grid.major.y = element_blank(),
panel.border = element_blank(),
axis.ticks.y = element_blank()) +
geom_text(aes(x = Group, y = PctHevac + 0.2 * sign(PctHevac),
label = paste0(round(PctHevac,1),"%")),
hjust = 0.1, vjust = -0.5, size = 3,
color=rgb(100,100,100, maxColorValue=255)) +
scale_y_continuous(labels = function(x) paste0(x, "%")) +
geom_hline(yintercept = pull(ri_flooded[8,6]), linetype = "dashed") +
geom_text(aes(x = "No Car HH", y = 11.5, label = "Below state avg"),
color = "gray48") +
geom_segment(aes(x = "Total Pop", xend = "Total Pop", y = 13, yend = 11),
arrow = arrow(length = unit(0.3,"cm"))) +
geom_text(aes(x = "Low Income", y = 14.7, label = "Above state avg"),
color = "gray48") +
geom_segment(aes(x = "Under 18", xend = "Under 18", y = 13.4, yend = 15),
arrow = arrow(length = unit(0.3,"cm")))
# Create map of pop over 64 exposed to flood hazard
# create raster of over 64 clipped to flood zones
floodOver64 <- ri_blkgrp_ras_list$over64Cell %>%
mask(., RI_FHZA_2840)
# map it out
tm_shape(RI_FHZA_2840) +
tm_fill(col = "blue", alpha = 0.3) +
tm_shape(floodOver64) + tm_raster(palette = "Reds",alpha = 0.7)
# Create map with blue ocean background color
tmap_mode("plot")
tm_layout(bg.color = "skyblue", saturation = .8) +
tm_shape(ri_blkgrp_2840) + tm_fill(col = "white") +
tm_shape(ne_states_sf_cb) + tm_fill(col="white") +
tm_shape(ri_awater_sf) + tm_fill(col = "skyblue", alpha = 0.3) +
tm_shape(ri_lwater_sf) + tm_lines(col = "skyblue", alpha = 0.3) +
tm_shape(floodOver64) +
tm_raster(palette = "Reds") +
tm_shape(ne_states_sf_cb) + tm_borders() +
tm_shape(ri_highways) + tm_lines(col = "seashell4", lwd = 2) +
tm_shape(I95roadSegment) +
tm_symbols(shape = I95, border.lwd = NA, size = 0.25) +
tm_shape(ri_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black",
xmod = 0.7, ymod = 0.2, shadow = TRUE)
# # export block groups to shapefile
# ri_blkgrp_fix <- st_make_valid(ri_blkrps_fix)
# class(ri_blkgrp_fix)
# ri_blkgrp_fix2 <- st_cast(ri_blkgrp_fix,"MULTIPOLYGON")
# ri_blkgrp_fix2 %>%
# dplyr::select(-starts_with("Shape")) %>%
# st_write(., dsn = "DATA/FEMA/RI/ri_blkgrp_fix09.shp",
# driver = "ESRI Shapefile", delete_layer = TRUE)
# # this works
# st_write(ri_localCon_sf, dsn = "DATA/FEMA/RI/ri_localCon_sf2.shp",
# driver = "ESRI Shapefile")
#
# ne_blkgrp_sf %>%
# dplyr::select(-starts_with("Shape")) %>%
# st_write(., dsn = "DATA/FEMA/RI/ne_blkgrp_sf4.shp", driver = "ESRI Shapefile", delete_layer = TRUE)
#
# library(maptools)
# ri_blkgrp_fix2_sp <- as_Spatial(ri_blkgrp_fix2)
# rgdal::writeOGR(ri_blkgrp_fix2_sp, dsn = "DATA/FEMA/RI",
# layer = "riTestsf3.shp", driver = "ESRI Shapefile",
# GDAL1_integer64_policy=TRUE)
###### REANALYSIS USING NLCD AS POLYGON LAYER
load("DATA/FEMA/RI/ri_fix.rds")
# Write out fixed block groups for processing in ArcGIS
ri_blkrps_fix %>%
dplyr::select(GEOID) %>%
st_write(., "DATA/FEMA/RI/ri_blkgrps_fix.shp", delete_layer = TRUE)
# repeat for tracts
ri_tracts_fix %>%
dplyr::select(GEOID) %>%
st_write(., "DATA/FEMA/RI/ri_tracts_fix.shp", delete_layer = TRUE)
# Perform NLCD raster-to-vector conversion, vector erase/difference, and vector intersections in ArcMap because it takes too long in R.
# Convert NLCD raster to shapefile. Isolate undeveloped areas.
# Erase areas of ri_blkgrp_fixed and ri_tracts_fixed that overlap with undeveloped areas in NLCD shapefiles. Compute OldArea of erased polygons in sqm to identify area of developed polygons remaining.
# Intersect ri_blkgrps and ri_tracts with NFHZA and Hurricane evacuation zones. Read back into R.
# read in processed ri_blkgrps and ri_tracts
st_layers(dsn = "DATA/FEMA/RI")
ri_blkgrps_nfhza <- st_read(dsn = "DATA/FEMA/RI",
layer = "ri_blkgrps_nfhza") %>%
left_join(., as.data.frame(ri_blkrps_fix), by = "GEOID") %>%
st_transform(., crs = 2840) %>%
mutate(NewArea = st_area(.)) %>%
st_make_valid()
ri_blkgrps_hevac <- st_read(dsn = "DATA/FEMA/RI",
layer = "ri_blkgrps_hevac") %>%
left_join(., as.data.frame(ri_blkrps_fix), by = "GEOID") %>%
st_transform(., crs = 2840) %>%
mutate(NewArea = st_area(.)) %>%
st_make_valid()
ri_tracts_nfhza <- st_read(dsn = "DATA/FEMA/RI",
layer = "ri_tracts_nfhza") %>%
left_join(., as.data.frame(ri_tracts_fix), by = "GEOID") %>%
st_transform(., crs = 2840) %>%
mutate(NewArea = st_area(.)) %>%
st_make_valid()
ri_tracts_hevac <- st_read(dsn = "DATA/FEMA/RI",
layer = "ri_tracts_hevac") %>%
left_join(., as.data.frame(ri_tracts_fix), by = "GEOID") %>%
st_transform(., crs = 2840) %>%
mutate(NewArea = st_area(.)) %>%
st_make_valid()
# Apportion populations based on geographic proportion of intersect
ri_blkgrps_nfhza <- ri_blkgrps_nfhza %>%
mutate(RI_LOWINC = if_else(RI_INCOME == "I",totalpopE,0)) %>%
mutate(RI_LOWINC = replace_na(RI_LOWINC,0)) %>%
mutate(RI_MINORITIES = if_else(RI_MINORITY == "M", totalpopE,0)) %>%
mutate(RI_MINORITIES = replace_na(RI_MINORITIES,0)) %>%
mutate(Proportion = as.numeric(NewArea/OldArea),
NewPop = totalpopE*Proportion,
NewMinority = minorityE*Proportion,
NewUnder5 = under5E*Proportion,
NewOver64 = over64E*Proportion,
NewUnder18 = under18E*Proportion,
NewEng_limit = eng_limitE*Proportion,
NewPov = num2povE*Proportion,
NewLths = lthsE*Proportion,
NewRI_LOWINC = RI_LOWINC*Proportion,
NewRI_MINORITIES = RI_MINORITIES*Proportion)
ri_blkgrps_hevac <- ri_blkgrps_hevac %>%
mutate(RI_LOWINC = if_else(RI_INCOME == "I",totalpopE,0)) %>%
mutate(RI_LOWINC = replace_na(RI_LOWINC,0)) %>%
mutate(RI_MINORITIES = if_else(RI_MINORITY == "M", totalpopE,0)) %>%
mutate(RI_MINORITIES = replace_na(RI_MINORITIES,0)) %>%
mutate(Proportion = as.numeric(NewArea/OldArea),
NewPop = totalpopE*Proportion,
NewMinority = minorityE*Proportion,
NewUnder5 = under5E*Proportion,
NewOver64 = over64E*Proportion,
NewUnder18 = under18E*Proportion,
NewEng_limit = eng_limitE*Proportion,
NewPov = num2povE*Proportion,
NewLths = lthsE*Proportion,
NewRI_LOWINC = RI_LOWINC*Proportion,
NewRI_MINORITIES = RI_MINORITIES*Proportion)
ri_tracts_nfhza <- ri_tracts_nfhza %>%
mutate(Proportion = as.numeric(NewArea/OldArea),
NewDisabled = disabledOver18E*Proportion,
NewNoCar = HHnoCarE*Proportion)
ri_tracts_hevac <- ri_tracts_hevac %>%
mutate(Proportion = as.numeric(NewArea/OldArea),
NewDisabled = disabledOver18E*Proportion,
NewNoCar = HHnoCarE*Proportion)
# Compute total block group populations within flood zones
ri_flood_blkgrp_df <- ri_blkgrps_nfhza %>%
as.data.frame() %>%
summarize(`Total Pop` = as.integer(sum(NewPop)),
Minority = as.integer(sum(NewMinority)),
`Under 5` = as.integer(sum(NewUnder5)),
`Over 64` = as.integer(sum(NewOver64)),
`Under 18` = as.integer(sum(NewUnder18)),
`Limited English HH` = as.integer(sum(NewEng_limit)),
`Low Income` = as.integer(sum(NewPov)),
`No HS Dip` = as.integer(sum(NewLths)),
`RI Low Income` = as.integer(sum(NewRI_LOWINC)),
`RI Minority` = as.integer(sum(NewRI_MINORITIES))) %>%
gather(key = Group, value = FloodPop)
# Compute total block group populations within hurricane evac zones
ri_hevac_blkgrp_df <- ri_blkgrps_hevac %>%
as.data.frame() %>%
summarize(`Total Pop` = as.integer(sum(NewPop)),
Minority = as.integer(sum(NewMinority)),
`Under 5` = as.integer(sum(NewUnder5)),
`Over 64` = as.integer(sum(NewOver64)),
`Under 18` = as.integer(sum(NewUnder18)),
`Limited English HH` = as.integer(sum(NewEng_limit)),
`Low Income` = as.integer(sum(NewPov)),
`No HS Dip` = as.integer(sum(NewLths)),
`RI Low Income` = as.integer(sum(NewRI_LOWINC)),
`RI Minority` = as.integer(sum(NewRI_MINORITIES))) %>%
gather(key = Group, value = HevacPop)
# Compute total tract populations within flood zones
ri_flood_tracts_df <- ri_tracts_nfhza %>%
as.data.frame() %>%
summarize(`Disabled` = as.integer(sum(NewDisabled)),
`No Car HH` = as.integer(sum(NewNoCar))) %>%
gather(key = Group, value = FloodPop)
ri_hevac_tracts_df <- ri_tracts_hevac %>%
as.data.frame() %>%
summarize(`Disabled` = as.integer(sum(NewDisabled)),
`No Car HH` = as.integer(sum(NewNoCar))) %>%
gather(key = Group, value = HevacPop)
# Compute total tract populations within the state for same groups
ri_tract_flood_pops_df <- ri_tracts_2840 %>%
as.data.frame() %>%
summarize(`Disabled` = sum(disabledOver18E),
`No Car HH` = sum(HHnoCarE)) %>%
gather(key = Group, value = RIPop) %>%
left_join(.,ri_flood_tracts_df, by = "Group")
ri_tract_hevac_pops_df <- ri_tracts_2840 %>%
as.data.frame() %>%
summarize(`Disabled` = sum(disabledOver18E),
`No Car HH` = sum(HHnoCarE)) %>%
gather(key = Group, value = RIPop) %>%
left_join(.,ri_hevac_tracts_df, by = "Group")
# Compute populations for state,and join with flood pops
ri_FloodPops_df <- ri_blkgrp_2840 %>%
as.data.frame() %>%
mutate(RI_LOWINC = if_else(RI_INCOME == "I",totalpopE,0)) %>%
mutate(RI_LOWINC = replace_na(RI_LOWINC,0)) %>%
mutate(RI_MINORITIES = if_else(RI_MINORITY == "M",totalpopE,0)) %>%
mutate(RI_MINORITIES = replace_na(RI_MINORITIES,0)) %>%
summarize(`Total Pop` = sum(totalpopE),
Minority = sum(minorityE),
`Under 5` = sum(under5E),
`Over 64` = sum(over64E),
`Under 18` = sum(under18E),
`Limited English HH` = sum(eng_limitE),
`Low Income` = sum(num2povE),
`No HS Dip` = sum(lthsE),
`RI Low Income` = sum(RI_LOWINC, na.rm = TRUE),
`RI Minority` = sum(RI_MINORITIES, na.rm = TRUE)) %>%
gather(key = Group, value = RIPop) %>%
left_join(., ri_flood_blkgrp_df, by = "Group") %>%
rbind(.,ri_tract_flood_pops_df) %>%
mutate(PctFlood = FloodPop/RIPop*100)
# Compute populations for state, and join with hurricane evac pops
ri_HevacPops_df <- ri_blkgrp_2840 %>%
as.data.frame() %>%
mutate(RI_LOWINC = if_else(RI_INCOME == "I",totalpopE,0)) %>%
mutate(RI_LOWINC = replace_na(RI_LOWINC,0)) %>%
mutate(RI_MINORITIES = if_else(RI_MINORITY == "M",totalpopE,0)) %>%
mutate(RI_MINORITIES = replace_na(RI_MINORITIES,0)) %>%
summarize(`Total Pop` = sum(totalpopE),
Minority = sum(minorityE),
`Under 5` = sum(under5E),
`Over 64` = sum(over64E),
`Under 18` = sum(under18E),
`Limited English HH` = sum(eng_limitE),
`Low Income` = sum(num2povE),
`No HS Dip` = sum(lthsE),
`RI Low Income` = sum(RI_LOWINC, na.rm = TRUE),
`RI Minority` = sum(RI_MINORITIES, na.rm = TRUE)) %>%
gather(key = Group, value = RIPop) %>%
left_join(., ri_hevac_blkgrp_df, by = "Group") %>%
rbind(.,ri_tract_hevac_pops_df) %>%
mutate(PctHevac = HevacPop/RIPop*100)
# Show table of pops within flood zones
ri_FloodPops_df %>%
arrange(-FloodPop)
# Create lollipop plot of pops within flood zones
ri_FloodPops_df %>%
ggplot(aes(x = reorder(Group,-PctFlood),
y = PctFlood)) +
geom_segment(aes(x = reorder(Group,-PctFlood),
xend = reorder(Group,-PctFlood),
y = ri_FloodPops_df[1,4], yend = PctFlood),
color = "skyblue") +
geom_point(color = "blue", size = 4, alpha = 0.8) +
coord_flip() + xlab("") + ylab("") +
ggtitle("Rhode Island Populations within Flood Zones") + theme_light() +
theme(panel.grid.major.y = element_blank(),
panel.border = element_blank(),
axis.ticks.y = element_blank()) +
geom_text(aes(x = Group, y = PctFlood + 0.2 * sign(PctFlood),
label = paste0(round(PctFlood,1),"%")),
hjust = 0.1, vjust = -0.5, size = 3,
color=rgb(100,100,100, maxColorValue=255)) +
scale_y_continuous(labels = function(x) paste0(x, "%")) +
geom_hline(yintercept = ri_FloodPops_df[1,4], linetype = "dashed") +
geom_text(aes(x = "Disabled", y = 7, label = "Below state avg"),
color = "gray48") +
geom_segment(aes(x = "No Car HH", xend = "No Car HH", y = 7.8, yend = 6),
arrow = arrow(length = unit(0.3,"cm"))) +
geom_text(aes(x = "Low Income", y = 8.8, label = "Above state avg"),
color = "gray48") +
geom_segment(aes(x = "Under 18", xend = "Under 18", y = 8, yend = 9.9),
arrow = arrow(length = unit(0.3,"cm")))
# Map elderly populations within floodzones
# tmap_mode("view")
# ri_blkgrps_nfhza %>%
# filter(NewOver64 > 0) %>%
# tm_shape(.) +
# tm_fill(col = "NewOver64", palette = "Reds", alpha = 0.8)
NewOver64_sf <- ri_blkgrps_nfhza %>%
filter(NewOver64 >= 1)
NewOver64_sf %>%
tm_shape(.) + tm_borders(col = "skyblue", lwd = 0.1, alpha = 0.3) +
tm_shape(NewOver64_sf) +
tm_fill("NewOver64", breaks = c(1,60,120,180,240,303),
style = "fixed", palette = "Reds", title = "Over 64") +
tm_shape(ne_states_sf_cb) + tm_borders() +
tm_shape(ri_highways) + tm_lines(col = "seashell4", lwd = 2) +
tm_shape(I95roadSegment) +
tm_symbols(shape = I95, border.lwd = NA, size = 0.25) +
tm_shape(I95roadSegment2) +
tm_symbols(shape = I95, border.lwd = NA, size = 0.25) +
tm_shape(I195roadSegment) +
tm_symbols(shape = I195, border.lwd = NA, size = 0.25) +
tm_shape(I295roadSegment) +
tm_symbols(shape = I295, border.lwd = NA, size = 0.25) +
tm_shape(ri_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black",
xmod = 0.7, ymod = 0.2, shadow = TRUE)
# Create map with blue ocean background color
tm_layout(bg.color = "skyblue", saturation = .8) +
tm_shape(ri_blkgrp_2840) + tm_fill(col = "white") +
tm_shape(ne_states_sf_cb) + tm_fill(col="white") +
tm_shape(ri_awater_sf) + tm_fill(col = "skyblue", alpha = 0.3) +
tm_shape(NewOver64_sf) +
tm_borders(col = "skyblue", lwd = 0.1, alpha = 0.3) +
tm_shape(NewOver64_sf) +
tm_fill("NewOver64", breaks = c(1,60,120,180,240,303),
style = "fixed", palette = "Reds", title = "Over 64") +
tm_shape(ne_states_sf_cb) + tm_borders() +
tm_shape(ri_highways) + tm_lines(col = "seashell4", lwd = 2) +
tm_shape(I95roadSegment) +
tm_symbols(shape = I95, border.lwd = NA, size = 0.25) +
tm_shape(I95roadSegment2) +
tm_symbols(shape = I95, border.lwd = NA, size = 0.25) +
tm_shape(I195roadSegment) +
tm_symbols(shape = I195, border.lwd = NA, size = 0.25) +
tm_shape(I295roadSegment) +
tm_symbols(shape = I295, border.lwd = NA, size = 0.25) +
tm_shape(ri_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black",
xmod = 0.7, ymod = 0.2, shadow = TRUE)
# Create a dot density map of total populations and overlay on flood zones
# Create random points, with 1 point for every 100 people
ri_totalpop_pts <- ri_blkgrp_2840 %>%
select(totalpopE) %>%
filter(totalpopE >= 100) %>%
st_sample(., size = round(.$totalpopE/100)) %>% # create 1 random point for every 100 people
st_sf(.) %>%
mutate(Group = "Total Pop")
# Map totalpop and flood zones
tm_layout(bg.color = "#e6f3f7") +
tm_shape(ri_blkgrp_2840, unit = "mi") + tm_fill(col = "white") +
tm_shape(ne_states_sf_cb) + tm_fill(col="white") +
tm_shape(ri_awater_sf) + tm_fill(col = "#e6f3f7") +
tm_shape(ne_states_sf_cb) + tm_borders() +
tm_shape(ri_totalpop_pts) + tm_dots(col = "forestgreen",
labels = "1 dot = 100 persons") +
tm_shape(ri_fhza_2840_land) +
tm_fill(col = "Interval",
palette = c("gold", "goldenrod3"),
labels = c("1% AEP (100-year)", "0.2% AEP (500-year)"),
title = "FEMA Flood Zones",
alpha = 0.6,
border.alpha = 0) +
tm_shape(ri_fhza_2840_land) +
tm_borders(col = "goldenrod1",
lwd = 0.5,
alpha = 0.6) +
tm_shape(ne_states_sf_cb) + tm_borders() +
tm_shape(ri_highways) + tm_lines(col = "seashell4", lwd = 2) +
tm_shape(I95roadSegment) +
tm_symbols(shape = I95, border.lwd = NA, size = 0.25) +
tm_shape(I95roadSegment2) +
tm_symbols(shape = I95, border.lwd = NA, size = 0.25) +
tm_shape(I195roadSegment) +
tm_symbols(shape = I195, border.lwd = NA, size = 0.25) +
tm_shape(I295roadSegment) +
tm_symbols(shape = I295, border.lwd = NA, size = 0.25) +
tm_shape(ri_towns_sf_pts) + tm_dots() +
tm_text("NAME", size = 0.5, col = "black",
xmod = 0.7, ymod = 0.2, shadow = TRUE) +
tm_scale_bar(breaks = c(0, 5, 10), text.size = 0.5,