-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransport_ConnecticutPDF.Rmd
6361 lines (5808 loc) · 350 KB
/
Transport_ConnecticutPDF.Rmd
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
---
title: "Transportation Options in Connecticut"
author: "Marcos Luna and Neenah Estrella-Luna"
date: "`r Sys.Date()`"
output:
bookdown::pdf_document2:
toc: true
toc_depth: 3
number_sections: true
fig_caption: yes
includes:
in_header: my_header.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=FALSE, message=FALSE, warning=FALSE)
library(tidyverse)
library(sf)
library(tmap)
library(tidytransit)
library(sp)
library(tigris)
options(tigris_use_cache = TRUE, tigris_class = "sf")
library(lubridate)
library(maptools)
library(spdep)
library(lwgeom)
```
\pagebreak
# Analysis of adequacy of public transit, walkability, and transportation cost burden in Connecticut
This is an analysis of access to public transit and walkability in Connecticut.
```{r data, include=FALSE}
### Analysis of Connecticut transportation options
load("DATA/ne_layers.rds")
# extract census units for state
ct_blkgrps_sf <- ne_blkgrp_sf %>%
filter(STATE == "Connecticut") %>%
select(GEOID, NAME,STATE, bg_area_m2, totalpopE, minorityE, under5E, under18E, over64E, householdsE, eng_hhE, eng_limitE, age25upE, lthsE, povknownE, num2povE, CT_INCOME) %>%
st_transform(., crs = 2775) %>%
filter(!st_is_empty(.)) %>%
mutate(PopAcre = totalpopE/(bg_area_m2*0.000247105))
ct_tracts_sf <- ne_tracts_sf %>%
filter(STATE == "Connecticut") %>%
select(GEOID, NAME, totalpopE, STATE, Over18E, disabledOver18E, totalHHE, HHnoCarE) %>%
st_transform(., crs = 2775) %>%
filter(!st_is_empty(.))
# clean up
rm(ne_blkgrp_sf,ne_tracts_sf,ne_blkgrp_sf90)
### Read in CT transit data from ... GTFS since state does not provide ready access to transit GIS files
# # Download GTFS data for CT Transit divisions: Hartford- New Haven - Stamford- New Britain - Waterbury - Meriden. URLS from CT Transit Developers page at https://www.cttransit.com/about/developers
# download.file(url = "https://www.cttransit.com/sites/default/files/gtfs/googlect_transit.zip", destfile = "DATA/transport/CT/CT_gtfs_files/CTTransit.zip")
# # Download GTFS data for Shore Line East - passenger rail service from New London to New Haven
# download.file(url = "https://shorelineeast.com/google_transit.zip", destfile = "DATA/transport/CT/CT_gtfs_files/ShorelineEast.zip")
# # Download GTFS data for Hartford Line Rail - passenger rail service from New Haven to Hartford to Springfield, CT
# download.file(url = "http://www.hartfordline.com/files/gtfs/gtfs.zip", destfile = "DATA/transport/CT/CT_gtfs_files/HartfordLine.zip")
# # Other public bus operations GTFS data from Open Mobility Data at https://transitfeeds.com/l/227-connecticut-usa
# # Download GTFS data for Estuary Transit District d.b.a. 9 Town Transit
# download.file(url = "http://data.trilliumtransit.com/gtfs/ninetown-connecticut-us/ninetown-connecticut-us.zip", destfile = "DATA/transport/CT/CT_gtfs_files/NineTownTransit.zip")
# # Download GTFS data for Greater Bridgeport Transit
# download.file(url = "http://data.trilliumtransit.com/gtfs/gbt-ct-us/gbt-ct-us.zip", destfile = "DATA/transport/CT/CT_gtfs_files/GBTransit.zip")
# # Download GTFS data for South East Area Transit District
# download.file(url = "http://data.trilliumtransit.com/gtfs/seatbus-ct-us/seatbus-ct-us.zip", destfile = "DATA/transport/CT/CT_gtfs_files/SEATTransit.zip")
# # Download GTFS data for New Haven Line - (operated by Metro-North) passenger rail service from New Haven to Greenwich and continuing to Grand Central Terminal, NYC. Branch line services to Waterbury, Danbury and New Canaan.
# download.file(url = "http://web.mta.info/developers/data/mnr/google_transit.zip", destfile = "DATA/transport/CT/CT_gtfs_files/NewHavenLine.zip")
#
# # Download CT Transit Waterbury division because it's not included in CT Transit package. Note that this version comes from Open Mobility Data, and is 2017 latest at https://transitfeeds.com/p/connecticut-transit/320?p=1
# download.file(url = "https://www.cttransit.com/sites/default/files/gtfs/googlewat_transit.zip", destfile = "DATA/transport/CT/CT_gtfs_files/CTWaterbury.zip")
# Download Norwalk Transit Transit District from https://transit.land/feed-registry/operators/o-dr7cc-norwalktransit
# download.file(url = "https://www.norwalktransit.com/s/GTFS_Data.zip", destfile = "DATA/transport/CT/CT_gtfs_files/NorwalkTransit.zip")
# create list of downloaded GTFS files
fileList <- as.list(list.files("DATA/transport/CT/CT_gtfs_files/", pattern = ".zip", full.names = TRUE))
# extract just file names without extension
fileListNames <- lapply(fileList,
function(x) fs::path_ext_remove(fs::path_file(x)))
# name items in fileList
fileList <- setNames(fileList,fileListNames)
# read in each file to gtfs
CT_gtfs_list <- lapply(fileList,
function(x) read_gtfs(x) %>%
gtfs_as_sf(.))
# add a table to the feed that indicates which service_id runs on which date. This is later useful for linking dates and trips via service_id.
CT_gtfs_list <- lapply(CT_gtfs_list, set_date_service_table)
# To understand service patterns better we need information on weekdays and holidays. With a calendar table we know the weekday and possible holidays for each date.
# create a function to generate calendar and join to date_servicepattern_table
calendarFunction <- function(thing) {
tibble(date = unique(thing$.$date_service_table$date)) %>%
mutate(
weekday = (function(date) {
c("Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday",
"Saturday")[as.POSIXlt(date)$wday + 1]
})(date)
) %>%
left_join(x = thing$.$date_servicepattern_table,y = ., by = "date", copy=TRUE)
}
# To analyse on which dates trips run and to group similar services we use service patterns. Such a pattern simply lists all dates a trip runs on. To handle these patterns we create a servicepattern_id using a hash function.
CT_gtfs_list <- lapply(CT_gtfs_list, set_servicepattern)
# Our gtfs feed now contains the data frame service_pattern which links each servicepattern_id to an existing service_id (and by extension trip_id).
# Understand patterns of service by visualising the data.
# Iterate over list to generate service pattern tables
date_servicepattern_table_list <- lapply(X = CT_gtfs_list, calendarFunction)
# This part has to be done manually for each item. sigh.
# create function to generate service pattern graph for each item
ggplotPatterns <- function (x) {
ggplot(x) + theme_bw() +
geom_point(aes(x = date, y = servicepattern_id, color = weekday), size = 1) +
scale_x_date(breaks = scales::date_breaks("1 month")) +
theme(legend.position = "bottom")
}
# iterate through list and create plot for each. look at each and identify M-F servcie pattern ids.
ggplotServicePatterns <- lapply(date_servicepattern_table_list, ggplotPatterns)
CTTransit_spids <- c("s_d945e55","s_d0e3ace","s_5bf4ea3")
CTWaterbury_spids <- "s_54e7696"
GBTransit_spids <- "s_c4a2c89"
HartfordLine_spids <- c("s5bcec03","s_4bef75b")
NewHavenLine_spids <- "s_0b4eda7"
NineTownTransit_spids <- c("s_73ab21e", "s_15bb852")
NorwalkTransit_spids <- "s_bb2cfdf"
SEATTransit_spids <- c("s_17d6f67", "s_113843a")
ShoreLineEast_spids <- c("s_f1b2485", "s_99ef7c2")
# create the list. make sure to remove spids_list before running, otherwise it gets included in the list!
spids_list <- mget(ls(pattern = "_spids"))
# iterate over list items to extract service ids
service_ids_list <- map2(CT_gtfs_list,spids_list,
function(x,y) x$.$service_pattern %>%
filter(servicepattern_id %in% y) %>%
pull(service_id))
# now that we’ve identified the set of service_id’s that refer to all weekday trips, we can summarize service between 6 am and 9 pm for bus service on weekdays.
# iterate over list items. skip Shore Line East because it's missing `direction-id` column
daily_stop_freq_list <- map2(CT_gtfs_list[-9],service_ids_list[-9],
function(x,y) get_stop_frequency(x, start_hour = 6, end_hour = 21, service_ids = y))
# # Convert stops to points for mapping
# Convert stops to points for mapping for each item in list
ct_transit_stops_sf_list <- lapply(X = CT_gtfs_list, function(x) stops_as_sf(x$stops))
# extract stops for Shore Line East, since it gets left out later
ShoreLineEast_stops_sf <- ct_transit_stops_sf_list$ShorelineEast
# Join headway frequencies to stops and route descriptions
# first, join headway frequencies
ct_transit_stops_sf_list <- map2(ct_transit_stops_sf_list[-9],daily_stop_freq_list,
function(x,y) x %>%
inner_join(y, by = "stop_id"))
# next, join route descriptions
ct_transit_stops_sf_list <- map2(ct_transit_stops_sf_list,CT_gtfs_list[-9],
function(x,y) x %>%
inner_join(y$routes, by = "route_id"))
# use the get_route_frequency function to summarize transit service by route, for the same time period.
# iterate over list items
daily_route_freq_list <- map2(CT_gtfs_list[-9],service_ids_list[-9],
function(x,y)
get_route_frequency(x, service_ids = y))
# Join the route frequencies to geometry for mapping
# iterate over list to extract route geometry. need to skip Hartford Line and Shoreline East because they're missing shapes.
ct_routes_sf_list <- map2(CT_gtfs_list[c(-4,-9)],service_ids_list[c(-4,-9)],
function(x,y) get_route_geometry(x, service_ids = y))
# join calculated frequencies to geometry and route descriptions
# first, join calculated frequencies to geometry. Again, skip Hartford Line and Shoreline East.
ct_routes_sf_list <- map2(ct_routes_sf_list, daily_route_freq_list[c(-4,-9)],
function(x,y) inner_join(x,y, by = "route_id"))
# next, join route descriptions to allow filtering
ct_routes_sf_list <- map2(ct_routes_sf_list,CT_gtfs_list[c(-4,-9)],
function(x,y)
inner_join(x,y$routes, by = "route_id"))
# Extract bus routes and common set of variables and combine into one layer
ct_routes_sf_Bus <- lapply(ct_routes_sf_list, function(x)
filter(x, route_type == 3) %>%
select(route_id:mean_headways,agency_id,route_short_name,route_long_name)) %>%
do.call(rbind, .) %>%
mutate(agency = case_when(
agency_id == "google-wa-me_transit" ~ "CT Transit Meriden/Wallingford",
agency_id == "googlestam_transit" ~ "CT Transit Stamford",
agency_id == "googleha_transit" ~ "CT Transit Hartford",
agency_id == "googlenh_transit" ~ "CT Transit New Haven",
agency_id == "googlenb_transit" ~ "CT Transit New Britain/Bristol",
agency_id == "7" ~ "CT Transit Waterbury",
agency_id == "668" ~ "Greater Bridgeport Transit",
agency_id == "1" ~ "New Haven Line",
agency_id == "539" ~ "9 Town Transit",
agency_id == "978" ~ "Southeast Area Transit",
agency_id == "0" ~ "Norwalk Transit"
)) %>%
st_transform(., crs = 2775) %>%
filter(!st_is_empty(.)) %>%
st_make_valid()
# create a simplified version for faster mapping
ct_routes_sf_Bus_simple <- unique(ct_routes_sf_Bus) %>%
group_by(route_short_name) %>%
summarize(agency = first(agency),agency_id = first(agency_id),mean_headways = mean(mean_headways,na.rm = TRUE)) %>%
st_make_valid()
# extract bus stops and merge to one layer
ct_stops_sf_Bus <- lapply(ct_transit_stops_sf_list, function(x)
filter(x, route_type == 3) %>%
select(agency_id,stop_id,route_type,headway)) %>%
do.call(rbind, .) %>%
mutate(agency = case_when(
agency_id == "google-wa-me_transit" ~ "CT Transit Meriden/Wallingford",
agency_id == "googlestam_transit" ~ "CT Transit Stamford",
agency_id == "googleha_transit" ~ "CT Transit Hartford",
agency_id == "googlenh_transit" ~ "CT Transit New Haven",
agency_id == "googlenb_transit" ~ "CT Transit New Britain/Bristol",
agency_id == "7" ~ "CT Transit Waterbury",
agency_id == "668" ~ "Greater Bridgeport Transit",
agency_id == "1" ~ "New Haven Line",
agency_id == "539" ~ "9 Town Transit",
agency_id == "978" ~ "Southeast Area Transit",
agency_id == "0" ~ "Norwalk Transit",
agency_id == "hartford-line" ~ "Hartford Line"
)) %>%
st_transform(., crs = 2775) %>%
filter(!st_is_empty(.)) %>%
st_make_valid()
# extract commuter rail stops and merge to one layer
ct_stops_sf_Rail <- lapply(ct_transit_stops_sf_list, function(x)
filter(x, route_type == 2) %>%
select(agency_id,stop_id,route_type,headway)) %>%
do.call(rbind, .) %>%
mutate(agency = case_when(
agency_id == "google-wa-me_transit" ~ "CT Transit Meriden/Wallingford",
agency_id == "googlestam_transit" ~ "CT Transit Stamford",
agency_id == "googleha_transit" ~ "CT Transit Hartford",
agency_id == "googlenh_transit" ~ "CT Transit New Haven",
agency_id == "googlenb_transit" ~ "CT Transit New Britain/Bristol",
agency_id == "7" ~ "CT Transit Waterbury",
agency_id == "668" ~ "Greater Bridgeport Transit",
agency_id == "1" ~ "New Haven Line",
agency_id == "539" ~ "9 Town Transit",
agency_id == "978" ~ "Southeast Area Transit",
agency_id == "0" ~ "Norwalk Transit",
agency_id == "hartford-line" ~ "Hartford Line"
)) %>%
st_transform(., crs = 2775) %>%
filter(!st_is_empty(.)) %>%
st_filter(.,ct_blkgrps_sf) %>% # filter out stops in New York!
st_make_valid()
# clean up
rm(list = ls(pattern = "_list|List|spids"))
# # Data acquired from CT DOT by Bradford Newtwon
# Load transit districts
ct_transit_districts <- st_read("DATA/transport/CT/NE_CT_Bus_Transit.gdb", "Transit_District_Boundaries") %>%
st_transform(., crs = 2775) %>%
st_make_valid()
#
# tm_shape(ct_transit_districts) + tm_fill(col = "Transit_District", alpha = 0.5)
# Load transit routes and stops
# st_layers("DATA/transport/CT/NE_CT_Bus_Transit.gdb")
NortheasternTransit_routes_sf <- st_read("DATA/transport/CT/NE_CT_Bus_Transit.gdb", "Northeastern_CT_Transit_District_Routes") %>%
st_transform(., crs = 2775) %>%
st_zm() %>%
transmute(geometry = Shape, route_id = NA, total_departures = NA, median_headways = NA, mean_headways = NA, agency_id = "windham", route_short_name = Bus_Route_Name, route_long_name = Bus_Route_Name, agency = Transit_District)
# change active geometry column from Shape to geometry
st_geometry(NortheasternTransit_routes_sf) <- "geometry"
# remove old Shape column
NortheasternTransit_routes_sf <- NortheasternTransit_routes_sf %>%
select(-Shape)
NortheasternTransit_stops_sf <- st_read("DATA/transport/CT/NE_CT_Bus_Transit.gdb", "Northeastern_CT_Transit_District_Bus_Stops") %>%
st_transform(., crs = 2775) %>%
st_zm() %>% # remove M dimension to allow rbind
transmute(geometry = Shape, agency_id = "net", stop_id = Stop_Num, route_type = 3, headway = NA, agency = Transit_District)
# change active geometry column from Shape to geometry
st_geometry(NortheasternTransit_stops_sf) <- "geometry"
# remove old Shape column
NortheasternTransit_stops_sf <- NortheasternTransit_stops_sf %>%
select(-Shape)
WindhamRegionTransit_routes_sf <- st_read("DATA/transport/CT/NE_CT_Bus_Transit.gdb", "Windham_Region_Transit_District_Routes") %>%
st_transform(., crs = 2775) %>%
st_zm() %>%
transmute(geometry = Shape, route_id = NA, total_departures = NA, median_headways = NA, mean_headways = NA, agency_id = "windham", route_short_name = Bus_Route_Name, route_long_name = Bus_Route_Name, agency = Transit_District)
# change active geometry column from Shape to geometry
st_geometry(WindhamRegionTransit_routes_sf) <- "geometry"
# remove old Shape column
WindhamRegionTransit_routes_sf <- WindhamRegionTransit_routes_sf %>%
select(-Shape)
WindhamRegionTransit_stops_sf <- st_read("DATA/transport/CT/NE_CT_Bus_Transit.gdb", "Windham_Region_Transit_District_Bus_Stops") %>%
st_transform(., crs = 2775) %>%
st_zm() %>% # remove M dimension to allow rbind
transmute(geometry = Shape, agency_id = "wind", stop_id = stop_id, route_type = 3, headway = NA, agency = Transit_District)
# change active geometry column from Shape to geometry
st_geometry(WindhamRegionTransit_stops_sf) <- "geometry"
# remove old Shape column
WindhamRegionTransit_stops_sf <- WindhamRegionTransit_stops_sf %>%
select(-Shape)
# merge all bus stops
ct_busStopsAll_sf <- rbind(ct_stops_sf_Bus,NortheasternTransit_stops_sf,
WindhamRegionTransit_stops_sf) %>%
st_filter(., ct_blkgrps_sf)
# merge all commuter rail stops
ct_trainStopsAll_sf <- ShoreLineEast_stops_sf %>%
transmute(agency_id = "shoreline", stop_id=stop_id, route_type = 2,
headway=NA, agency="Shoreline East") %>%
st_transform(., crs = 2775) %>%
rbind(ct_stops_sf_Rail,.) %>%
st_filter(., ct_blkgrps_sf) %>%
st_make_valid()
# merge all bus routes
ct_busRoutesAll_sf <- rbind(ct_routes_sf_Bus, NortheasternTransit_routes_sf, WindhamRegionTransit_routes_sf)
# load rail from CT CTGIC at http://magic.lib.uconn.edu/connecticut_data.html#roads (based on Census 2010)
Railroad_sf <- st_read("DATA/transport/CT/railct_37800_0000_2010_s100_census_1_shp/NAD83", "railct_37800_0000_2010_s100_census_1_shp_nad83_feet") %>%
st_transform(., crs = 2775)
# filter(FULLNAME %in% c("Conrail RR","Penn Central RR","Metro North RR","Amtrak RR"))
# # or grab more recent rail from TIGER\Line, but does not distinguish passenger rail service, just physical rail
# rail_sf <- tigris::rails()
# clean up
# rm(list = ls(pattern = "rail|Rail"))
# Use dasymetric mapping to calculate populations with access to transit. Approach follows method used by Qiang (2019) to eliminate unpopulated areas of census polygons and then reallocate populations to developed areas as identified in National Land Cover Dataset (NLCD).
# Perform NLCD raster-to-vector conversion, vector erase/difference, and vector intersections in ArcMap because it takes too long in R.
# In ArcMap:
# Convert NLCD raster to shapefile. Clip to state.
# Isolate undeveloped areas (gridcode NOT 22 - 24).
# Erase areas of block groups and tracts that overlap with undeveloped areas in NLCD shapefiles. Compute OldArea of erased polygons in sqm to identify area of developed polygons remaining.
##### Return to working in R ######
# # read in processed ct_blkgrps and ct_tracts
# st_layers(dsn = "DATA/FEMA/CT")
ct_blkgrps_developed <- st_read(dsn = "DATA/FEMA/CT",
layer = "ct_blkgrps_developed")
ct_blkgrps_developed <- ct_blkgrps_sf %>%
mutate(CT_LOWINC = if_else(CT_INCOME == "I", totalpopE, 0)) %>%
mutate(CT_LOWINC = replace_na(CT_LOWINC,0)) %>%
as.data.frame() %>%
dplyr::select(-geometry) %>%
left_join(ct_blkgrps_developed, ., by = "GEOID") %>%
st_transform(., crs = 2775) %>%
mutate(NewArea = st_area(.)) %>%
st_make_valid() %>%
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,
NewCT_LOWINC = CT_LOWINC*Proportion,
NewPopAcre = NewPop/(NewArea*0.000247105))
ct_tracts_developed <- st_read(dsn = "DATA/FEMA/CT",
layer = "ct_tracts_developed") %>%
left_join(., as.data.frame(ct_tracts_sf), by = "GEOID") %>%
st_transform(., crs = 2775) %>%
mutate(NewArea = st_area(.)) %>%
st_make_valid() %>%
mutate(Proportion = as.numeric(NewArea/OldArea),
NewDisabled = disabledOver18E*Proportion,
NewOver18 = Over18E*Proportion,
NewHHNoCar = HHnoCarE*Proportion)
# create a simplified version for faster mapping
ct_blkgrps_developed_simple <- st_simplify(ct_blkgrps_developed,
dTolerance = 100) %>%
filter(!st_is_empty(.)) %>%
st_make_valid()
# repeat for tracts
ct_tracts_developed_simple <- st_simplify(ct_tracts_developed,
dTolerance = 100) %>%
filter(!st_is_empty(.)) %>%
st_make_valid()
# Create a 400m buffer around bus stops
ct_busBuff400m <- st_buffer(ct_busStopsAll_sf,dist = 400) %>%
st_union() %>%
st_as_sf()
# Create buffers around commuter rail stops (4800m)
ct_crBuff4800m <- st_buffer(ct_trainStopsAll_sf, dist = 4800) %>%
st_union() %>%
st_as_sf()
ct_transitAllBuff <- rbind(ct_busBuff400m,
ct_crBuff4800m) %>%
st_union() %>%
st_as_sf() %>%
mutate(Sqm = st_area(.))
# Use areal interpolation to calculate priority populations within buffer of accessibility
ct_busBuff400m_sf <- ct_blkgrps_developed %>%
select(GEOID,NewArea:NewCT_LOWINC) %>%
mutate(OldArea = NewArea) %>%
st_intersection(ct_busBuff400m,.) %>%
mutate(NewArea = st_area(.),
Proportion = NewArea/OldArea,
NewPop = as.integer(NewPop*Proportion),
NewMinority = as.integer(NewMinority*Proportion),
NewUnder5 = as.integer(NewUnder5*Proportion),
NewOver64 = as.integer(NewOver64*Proportion),
NewUnder18 = as.integer(NewUnder18*Proportion),
NewEng_limit = as.integer(NewEng_limit*Proportion),
NewPov = as.integer(NewPov*Proportion),
NewLths = as.integer(NewLths*Proportion),
NewCT_LOWINC = as.integer(NewCT_LOWINC*Proportion))
ct_crBuff4800m_sf <- ct_blkgrps_developed %>%
select(GEOID,NewArea:NewCT_LOWINC) %>%
mutate(OldArea = NewArea) %>%
st_intersection(ct_crBuff4800m,.) %>%
mutate(NewArea = st_area(.),
Proportion = NewArea/OldArea,
NewPop = as.integer(NewPop*Proportion),
NewMinority = as.integer(NewMinority*Proportion),
NewUnder5 = as.integer(NewUnder5*Proportion),
NewOver64 = as.integer(NewOver64*Proportion),
NewUnder18 = as.integer(NewUnder18*Proportion),
NewEng_limit = as.integer(NewEng_limit*Proportion),
NewPov = as.integer(NewPov*Proportion),
NewLths = as.integer(NewLths*Proportion),
NewCT_LOWINC = as.integer(NewCT_LOWINC*Proportion))
ct_TransitAllBuff_sf <- ct_blkgrps_developed %>%
select(GEOID,NewArea:NewCT_LOWINC) %>%
mutate(OldArea = NewArea) %>%
st_intersection(ct_transitAllBuff,.) %>%
mutate(NewArea = st_area(.),
Proportion = NewArea/OldArea,
NewPop = as.integer(NewPop*Proportion),
NewMinority = as.integer(NewMinority*Proportion),
NewUnder5 = as.integer(NewUnder5*Proportion),
NewOver64 = as.integer(NewOver64*Proportion),
NewUnder18 = as.integer(NewUnder18*Proportion),
NewEng_limit = as.integer(NewEng_limit*Proportion),
NewPov = as.integer(NewPov*Proportion),
NewLths = as.integer(NewLths*Proportion),
NewCT_LOWINC = as.integer(NewCT_LOWINC*Proportion))
# Repeat for tracts
ct_busBuff400mTracts_sf <- ct_tracts_developed %>%
select(GEOID,NewDisabled:NewHHNoCar) %>%
mutate(OldArea = st_area(.)) %>%
st_intersection(ct_busBuff400m,.) %>%
mutate(NewArea = st_area(.),
Proportion = NewArea/OldArea,
NewDisabled = as.integer(NewDisabled*Proportion),
NewNoCar = as.integer(NewHHNoCar*Proportion))
ct_crBuff4800mTracts_sf <- ct_tracts_developed %>%
select(GEOID,NewDisabled:NewHHNoCar) %>%
mutate(OldArea = st_area(.)) %>%
st_intersection(ct_crBuff4800m,.) %>%
mutate(NewArea = st_area(.),
Proportion = NewArea/OldArea,
NewDisabled = as.integer(NewDisabled*Proportion),
NewNoCar = as.integer(NewHHNoCar*Proportion))
ct_TransitAllBuffTracts_sf <- ct_tracts_developed %>%
select(GEOID,NewDisabled:NewHHNoCar) %>%
mutate(OldArea = st_area(.)) %>%
st_intersection(ct_transitAllBuff,.) %>%
mutate(NewArea = st_area(.),
Proportion = NewArea/OldArea,
NewDisabled = as.integer(NewDisabled*Proportion),
NewNoCar = as.integer(NewHHNoCar*Proportion))
# Compute total block group populations within transit stop buffers
ct_busBuff400m_df <- ct_busBuff400m_sf %>%
as.data.frame() %>%
summarize(`Total Pop` = sum(NewPop),
Minority = sum(NewMinority),
`Under 5` = sum(NewUnder5),
`Over 64` = sum(NewOver64),
`Under 18` = sum(NewUnder18),
`Limited English HH` = sum(NewEng_limit),
`Low Income` = sum(NewPov),
`No HS Dip` = sum(NewLths),
`CT Low Income` = sum(NewCT_LOWINC)) %>%
gather(key = Group, value = BusPop)
ct_crBuff4800m_df <- ct_crBuff4800m_sf %>%
as.data.frame() %>%
summarize(`Total Pop` = sum(NewPop),
Minority = sum(NewMinority),
`Under 5` = sum(NewUnder5),
`Over 64` = sum(NewOver64),
`Under 18` = sum(NewUnder18),
`Limited English HH` = sum(NewEng_limit),
`Low Income` = sum(NewPov),
`No HS Dip` = sum(NewLths),
`CT Low Income` = sum(NewCT_LOWINC)) %>%
gather(key = Group, value = CommuterPop)
ct_TransitAllBuff_df <- ct_TransitAllBuff_sf %>%
as.data.frame() %>%
summarize(`Total Pop` = sum(NewPop),
Minority = sum(NewMinority),
`Under 5` = sum(NewUnder5),
`Over 64` = sum(NewOver64),
`Under 18` = sum(NewUnder18),
`Limited English HH` = sum(NewEng_limit),
`Low Income` = sum(NewPov),
`No HS Dip` = sum(NewLths),
`CT Low Income` = sum(NewCT_LOWINC)) %>%
gather(key = Group, value = TransitPop)
# Compute total tract populations within bus stop buffer
ct_busBuff400mTracts_df <- ct_busBuff400mTracts_sf %>%
as.data.frame() %>%
summarize(`Disabled` = sum(NewDisabled),
`No Car HH` = sum(NewNoCar)) %>%
gather(key = Group, value = BusPop)
ct_crBuff4800mTracts_df <- ct_crBuff4800mTracts_sf %>%
as.data.frame() %>%
summarize(`Disabled` = sum(NewDisabled),
`No Car HH` = sum(NewNoCar)) %>%
gather(key = Group, value = CommuterPop)
ct_TransitAllBuffTracts_df <- ct_TransitAllBuffTracts_sf %>%
as.data.frame() %>%
summarize(`Disabled` = sum(NewDisabled),
`No Car HH` = sum(NewNoCar)) %>%
gather(key = Group, value = TransitPop)
# Compute total tract populations within the state for same groups
ct_tract_pops_df <- ct_tracts_sf %>%
as.data.frame() %>%
summarize(`Disabled` = sum(disabledOver18E),
`No Car HH` = sum(HHnoCarE)) %>%
gather(key = Group, value = CTPop) %>%
left_join(.,ct_busBuff400mTracts_df, by = "Group") %>%
left_join(.,ct_crBuff4800mTracts_df, by = "Group") %>%
left_join(.,ct_TransitAllBuffTracts_df, by = "Group")
# Compute populations for state, join with buffer pops
ct_transitAccessPops_df <- ct_blkgrps_sf %>%
as.data.frame() %>%
mutate(CT_LOWINC = if_else(CT_INCOME == "I", totalpopE, 0)) %>%
mutate(CT_LOWINC = replace_na(CT_LOWINC,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),
`CT Low Income` = sum(CT_LOWINC, na.rm = TRUE)) %>%
gather(key = Group, value = CTPop) %>%
left_join(., ct_busBuff400m_df, by = "Group") %>%
left_join(., ct_crBuff4800m_df, by = "Group") %>%
left_join(., ct_TransitAllBuff_df, by = "Group") %>%
rbind(.,ct_tract_pops_df) %>%
mutate(PctBus = BusPop/CTPop*100,
PctCommuter = CommuterPop/CTPop*100,
PctAllTransit = TransitPop/CTPop*100)
# create point layer of towns for context
ct_towns_sf_pts <- county_subdivisions(state = "CT", cb = TRUE) %>%
filter(NAME %in% c("Hartford",
"Stamford",
"Fairfield",
"Bridgeport",
"New Haven",
"Danbury",
"Hamden",
"Meriden",
"Waterbury",
"New Britain",
"New London",
"Norwich",
"North Canaan",
"Old Saybrook",
"Greenwich")) %>%
st_transform(., crs = 2775) %>%
st_centroid(of_largest_polygon = TRUE)
# Create road layer for context
ct_highways <- primary_roads() %>%
filter(FULLNAME %in% c("I- 84","I- 91","I- 95","I- 395")) %>%
tmaptools::crop_shape(., ne_states_sf_cb) %>%
st_transform(., crs = 2775)
# group_by(FULLNAME) %>%
# summarize(RTTYP = unique(RTTYP),
# MTFCC = unique(MTFCC))
# Extract highway segments for labeling
I84roadSegment <- ct_highways %>%
filter(LINEARID == "1105281313426")
I91roadSegment <- ct_highways %>%
filter(LINEARID == "1104470395750")
I95roadSegment <- ct_highways %>%
filter(LINEARID == "11013782168181")
I95roadSegment2 <- ct_highways %>%
filter(LINEARID == "1105281377007")
I395roadSegment <- ct_highways %>%
filter(LINEARID == "1104493001068")
# 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")
I395 <- tmap_icons("https://upload.wikimedia.org/wikipedia/commons/thumb/1/16/I-395.svg/200px-I-395.svg.png")
I91 <- tmap_icons("https://upload.wikimedia.org/wikipedia/commons/thumb/9/90/I-91.svg/200px-I-91.svg.png")
I84 <- tmap_icons("https://upload.wikimedia.org/wikipedia/commons/thumb/5/51/I-84.svg/200px-I-84.svg.png")
# # recode routes to match CTPTA categories
# ct_busroutes_sf <- ct_busroutes_sf %>%
# mutate(type = case_when(
# ROUTE %in% c(3,4,6,13,17,18,19,21,22,29,30,32,33,34,35,40,49,51,55,57,58,63,64,67,72,73,75,76,78,80,87) ~ "Urban Service",
# ROUTE == 11 ~ "Rapid Line",
# ROUTE %in% c(8,9,10,12,14,54,59,60,61,62,65,66,95) ~ "Express Service",
# ROUTE %in% c(1,20,27,28,31,50,56,71,92) ~ "Key Corridor",
# ROUTE %in% c(16,203,204,210,231,242,281,282,301) ~ "Flex Service"))
# Calculate totals of priority populations for use in computing percentages in later tables
# Calculate tract populations by state
statepopsdf_tracts <- ct_tracts_sf %>%
as.data.frame() %>%
group_by(STATE) %>%
summarize(TotalDisabled = sum(disabledOver18E, na.rm = TRUE),
TotalOver18 = sum(Over18E, na.rm = TRUE),
TotalNoCar = sum(HHnoCarE, na.rm = TRUE))
statepopsdf <- ct_blkgrps_sf %>%
as.data.frame() %>%
mutate(CT_LOWINC = if_else(CT_INCOME == "I", totalpopE, 0)) %>%
mutate(CT_LOWINC = replace_na(CT_LOWINC,0)) %>%
group_by(STATE) %>%
summarize(TotalPop = sum(totalpopE, na.rm = TRUE),
TotalHH = sum(householdsE, na.rm = TRUE),
TotalLEH = sum(eng_limitE, na.rm = TRUE),
TotalMin = sum(minorityE, na.rm = TRUE),
TotalLowInc = sum(num2povE, na.rm = TRUE),
TotalNoHS = sum(lthsE, na.rm = TRUE),
TotalOver64 = sum(over64E, na.rm = TRUE),
TotalUnder5 = sum(under5E, na.rm = TRUE),
TotalUnder18 = sum(under18E, na.rm = TRUE),
TotalCT_LOWINC = sum(CT_LOWINC, na.rm = TRUE)) %>%
left_join(., statepopsdf_tracts,by="STATE")
# ct_towns_sf <- ne_towns_sf %>%
# dplyr::select(GEOID,NAME) %>%
# st_transform(., crs = 2775)
ct_towns_sf <- county_subdivisions(state = "CT", cb = TRUE) %>%
st_transform(., crs = 2775)
townpopsdf_tracts <- ct_tracts_sf %>%
st_centroid(.) %>%
st_intersection(ct_towns_sf,.) %>%
as.data.frame() %>%
group_by(NAME) %>%
summarize(TotalDisabled = sum(disabledOver18E, na.rm = TRUE),
TotalOver18 = sum(Over18E, na.rm = TRUE),
TotalNoCar = sum(HHnoCarE, na.rm = TRUE))
townpopsdf <- ct_blkgrps_sf %>%
dplyr::select(-GEOID) %>%
st_centroid(.) %>%
st_intersection(ct_towns_sf,.) %>%
as.data.frame() %>%
mutate(CT_LOWINC = if_else(CT_INCOME == "I", totalpopE, 0)) %>%
mutate(CT_LOWINC = replace_na(CT_LOWINC,0)) %>%
group_by(NAME) %>%
summarize(GEOID = unique(GEOID),
TotalPop = sum(totalpopE, na.rm = TRUE),
TotalHH = sum(householdsE, na.rm = TRUE),
TotalLEH = sum(eng_limitE, na.rm = TRUE),
TotalMin = sum(minorityE, na.rm = TRUE),
TotalLowInc = sum(num2povE, na.rm = TRUE),
TotalNoHS = sum(lthsE, na.rm = TRUE),
TotalOver64 = sum(over64E, na.rm = TRUE),
TotalUnder5 = sum(under5E, na.rm = TRUE),
TotalUnder18 = sum(under18E, na.rm = TRUE),
TotalCT_LOWINC = sum(CT_LOWINC, na.rm = TRUE)) %>%
left_join(.,townpopsdf_tracts,by="NAME")
ct_state_sf_cb <- ne_states_sf_cb %>%
filter(NAME == "Connecticut") %>%
st_transform(., crs = st_crs(ct_blkgrps_sf))
# Identify areas >= 1 mile from bus stops
# Create a 1 mile buffer around bus stops
ct_busBuff1mile <- st_buffer(ct_busStopsAll_sf,dist = 1609.34) %>%
st_union() %>%
st_as_sf()
# identify block groups that do not intersect with 1 mile from bus stop
ct_blkgrps_sf_noBus <- ct_blkgrps_developed %>%
filter(st_disjoint(.,ct_busBuff1mile,sparse = FALSE))
# Identify tracts that do not intersect with buffer
ct_tracts_sf_noBus <- ct_tracts_developed %>%
filter(st_disjoint(.,ct_busBuff1mile,sparse = FALSE))
# create simplified versions for faster mapping
ct_blkgrps_sf_noBus_simple <- ct_blkgrps_sf_noBus %>%
st_simplify(., dTolerance = 100) %>%
filter(!st_is_empty(.)) %>%
st_make_valid()
ct_tracts_sf_noBus_simple <- ct_tracts_sf_noBus %>%
st_simplify(., dTolerance = 100) %>%
filter(!st_is_empty(.)) %>%
st_make_valid()
# Identify areas >= 10 miles from commuter rail stops
ct_crBuff10mile <- ct_trainStopsAll_sf %>%
st_buffer(., dist = (10*1609.34)) %>%
st_union() %>%
st_as_sf()
# identify block groups that do not intersect with 10 mile buffer
ct_blkgrps_sf_noCR <- ct_blkgrps_developed %>%
filter(st_disjoint(.,ct_crBuff10mile,sparse = FALSE))
# create simplified version of block groups for faster mapping
ct_blkgrps_sf_noCR_simple <- ct_blkgrps_sf_noCR %>%
select(NewPop:NewCT_LOWINC) %>%
st_simplify(., dTolerance = 100) %>%
filter(!st_is_empty(.)) %>%
st_make_valid()
# identify tracts that do not intersect with 10 mile buffer
ct_tracts_sf_noCR <- ct_tracts_developed %>%
filter(st_disjoint(.,ct_crBuff10mile,sparse = FALSE))
# create simplified version of tracts for faster mapping
ct_tracts_sf_noCR_simple <- ct_tracts_sf_noCR %>%
select(NewDisabled:NewHHNoCar) %>%
st_simplify(., dTolerance = 100) %>%
filter(!st_is_empty(.)) %>%
st_make_valid()
# Identify areas with no access to any type of transit stop. Union all buffers to create one buffer and clip to state boundary.
ct_transitBuffAll <- rbind(ct_busBuff1mile,
ct_crBuff10mile) %>%
st_union() %>%
st_as_sf() %>%
tmaptools::crop_shape(.,ct_state_sf_cb,polygon = TRUE)
# identify block groups that do not intersect with any transit buffer
ct_blkgrps_sf_noTransit <- ct_blkgrps_developed %>%
filter(st_disjoint(.,ct_transitBuffAll,sparse = FALSE))
# identify tracts that do not intersect with 5 mile buffer
ct_tracts_sf_noTransit <- ct_tracts_developed %>%
filter(st_disjoint(.,ct_transitBuffAll,sparse = FALSE))
# create simplified versions for faster mapping
ct_blkgrps_sf_noTransit_simple <- ct_blkgrps_sf_noTransit %>%
st_simplify(., dTolerance = 100) %>%
filter(!st_is_empty(.)) %>%
st_make_valid()
ct_tracts_sf_noTransit_simple <- ct_tracts_sf_noTransit %>%
st_simplify(., dTolerance = 100) %>%
filter(!st_is_empty(.)) %>%
st_make_valid()
# write out to file for later analysis
save(ct_blkgrps_sf_noTransit, ct_tracts_sf_noTransit,
ct_blkgrps_sf_noBus,ct_transitAccessPops_df,ct_busBuff400m_sf,
file = "DATA/transport/CT/noTransit.Rds")
```
## Access to Public Transit
This analysis seeks to identify communities that are underserved by access to public transit. Access to transit is measured in terms of distance to transit boarding stops and in terms of frequency of service.
Connecticut is served by 19 local bus agencies or transit districts, four rail lines, ferries, and two private inter-city bus services. The analysis presented here only considers transit services for which publicly available geospatial data is available, which includes `r length(unique(ct_busStopsAll_sf$agency))`
regional public transit agencies and two rail services. Amtrak train service passes through Connecticut as well. Ferry services, water taxis, and other seasonal transportation services are not considered in this analysis. Figure \@ref(fig:transitMap) shows `r formatC(nrow(ct_busRoutesAll_sf),big.mark = ",")` fixed public transit routes across the state along with population density.
```{r transitMap, fig.align = "center", fig.cap="Transit service and population density in Connecticut."}
# bbox_new <- st_bbox(ct_blkgrps_sf) # current bounding box
#
# xrange <- bbox_new$xmax - bbox_new$xmin # range of x values
# yrange <- bbox_new$ymax - bbox_new$ymin # range of y values
#
# # bbox_new[1] <- bbox_new[1] - (2.2 * xrange) # xmin - left
# # bbox_new[3] <- bbox_new[3] + (2 * xrange) # xmax - right
# bbox_new[2] <- bbox_new[2] - (0.2 * yrange) # ymin - bottom
# # bbox_new[4] <- bbox_new[4] + (2 * yrange) # ymax - top
#
# bbox_new <- bbox_new %>% # take the bounding box ...
# st_as_sfc() # ... and make it a sf polygon
# m <- tm_shape(ct_towns_sf, unit = "mi") +
# tm_borders(col = "gray", lwd = 0.2) +
# tm_shape(ct_blkgrps_developed_simple) +
# tm_fill(col = "NewPopAcre", style = "quantile",
# colorNA = "white", colorNULL = "gray", title = "Pop per Acre",
# legend.format = list(fun = function(x) formatC(x, digits = 1, format = "f")), palette = "YlGn") +
# tm_shape(ne_states_sf_cb) + tm_borders(lwd = 0.2, alpha = 0.8) +
# tm_text("STUSPS", size = 0.7, remove.overlap = TRUE, col = "gray") +
# tm_shape(ct_highways) + tm_lines(col = "seashell4", alpha = 0.7) +
# tm_shape(ct_busRoutesAll_sf) + tm_lines(col = "coral", lwd = 1) +
# tm_shape(Railroad_sf) + tm_lines(lty = "twodash", lwd = 0.5) +
# tm_shape(ct_stops_sf_Rail) + tm_dots(col = "red", size = 0.1) +
# tm_shape(I95roadSegment) +
# tm_symbols(shape = I95, border.lwd = NA, size = 0.1) +
# tm_shape(I95roadSegment2) +
# tm_symbols(shape = I95, border.lwd = NA, size = 0.1) +
# tm_shape(I395roadSegment) +
# tm_symbols(shape = I395, border.lwd = NA, size = 0.1) +
# tm_shape(I91roadSegment) +
# tm_symbols(shape = I91, border.lwd = NA, size = 0.1) +
# tm_shape(I84roadSegment) +
# tm_symbols(shape = I84, border.lwd = NA, size = 0.1) +
# tm_shape(ct_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, 10, 20), text.size = 0.5,
# position = c(0.6,0.005)) +
# tm_add_legend(type = "line", labels = "Bus Routes", col = "coral") +
# tm_add_legend(type = "line", lty = "twodash", labels = "Rail") +
# tm_add_legend(type = "symbol", labels = "Rail Stops", col = "red", size = 0.2) +
# tm_layout(title = "Connecticut\nTransit Routes\nand Population\nDensity",
# frame = FALSE, main.title.size = 0.8,
# legend.outside = TRUE,
# legend.title.size = 0.8,
# legend.outside.position = c("right", "top"))
#
# tmap_save(m, "DATA/transport/CT/figures/ct_transit.png",
# height = 4, width = 8, units = "in", dpi = 600)
knitr::include_graphics("DATA/transport/CT/figures/ct_transit.png")
```
Approximately `r round(ct_transitAccessPops_df %>% filter(Group == "Total Pop") %>% select(PctAllTransit) %>% pull(),0)`% of the state population have reasonable access to some form of transit, but this access varies by mode. For example, only `r paste0(round(ct_transitAccessPops_df %>% filter(Group == "Total Pop") %>% dplyr::select(PctBus) %>% pull(),1),"%")` of the state population lives within reasonable walking distance of a bus stop (defined as approximately 400 meters or 1/4 mile).
Figures \@ref(fig:loliBusDist) to \@ref(fig:loliAllTransitDist) below compare the percentages of different population groups living within reasonable walking distance of bus stops (1/4 mile) and commuter rail stops (3 miles) across the state, respectively. Most priority populations, including transit-dependent groups, have access similar to or better than the general population. However, note that people over age 64 and under 18 have consistently less access to transit on average compared to the general population.
```{r loliBusDist, echo=FALSE, message=FALSE, warning=FALSE, fig.align = "center", fig.cap="Percentage of population groups within 1/4 mile (400 meters) of a bus stop across Connecticut."}
ct_transitAccessPops_df %>%
mutate(Group = recode(Group, "Minority" = "People of Color",
"No HS Dip" = "No HS Diploma")) %>%
ggplot(aes(x = reorder(Group,-PctBus),
y = PctBus)) +
geom_segment(aes(x = reorder(Group,-PctBus), xend = reorder(Group,-PctBus),
y = ct_transitAccessPops_df[1,6], yend = PctBus),
color = "skyblue") +
geom_point(color = "blue", size = 4, alpha = 0.8) +
coord_flip() + xlab("") + ylab("") + ggtitle("Connecticut Populations within Walking Distance\n(400m) of Bus Stops") + theme_light() +
theme(panel.grid.major.y = element_blank(),
panel.border = element_blank(),
axis.ticks.y = element_blank()) +
geom_text(aes(x = Group, y = PctBus + 0.2 * sign(PctBus),
label = paste0(round(PctBus,0),"%")),
hjust = -0.2, vjust = -.4, size = 3,
color=rgb(100,100,100, maxColorValue=255)) +
scale_y_continuous(labels = function(x) paste0(x, "%")) +
geom_hline(yintercept = ct_transitAccessPops_df[1,6], linetype = "dashed") +
geom_text(aes(x = "Total Pop", y = 40, label = "Above state\naverage"),
color = "gray48") +
geom_text(aes(x = "Total Pop", y = 22, label = "Below state\naverage"),
color = "gray48") +
expand_limits(y = c(20,65))
ggsave("images/CT_Bus_graph.png")
```
```{r loliCRDist, echo=FALSE, message=FALSE, warning=FALSE, fig.align = "center", fig.cap="Percentage of population groups within 3 miles (4800 meters) of a commuter rail stop."}
ct_transitAccessPops_df %>%
mutate(Group = recode(Group, "Minority" = "People of Color",
"No HS Dip" = "No HS Diploma")) %>%
ggplot(aes(x = reorder(Group,-PctCommuter),
y = PctCommuter)) +
geom_segment(aes(x = reorder(Group,-PctCommuter), xend = reorder(Group,-PctCommuter),
y = ct_transitAccessPops_df[1,7], yend = PctCommuter),
color = "skyblue") +
geom_point(color = "blue", size = 4, alpha = 0.8) +
coord_flip() + xlab("") + ylab("") + ggtitle("Connecticut Populations within 3 miles (4800m)\nof Commuter Rail Stops") + theme_light() +
theme(panel.grid.major.y = element_blank(),
panel.border = element_blank(),
axis.ticks.y = element_blank()) +
geom_text(aes(x = Group, y = PctCommuter + 0.2 * sign(PctCommuter),
label = paste0(round(PctCommuter,0),"%")),
hjust = -0.2, vjust = -.4, size = 3,
color=rgb(100,100,100, maxColorValue=255)) +
scale_y_continuous(labels = function(x) paste0(x, "%")) +
geom_hline(yintercept = ct_transitAccessPops_df[1,7], linetype = "dashed") +
geom_text(aes(x = "Total Pop", y = 58, label = "Above state\naverage"),
color = "gray48") +
geom_text(aes(x = "Total Pop", y = 40, label = "Below state\naverage"),
color = "gray48") +
expand_limits(y = c(35,75))
ggsave("images/CT_CR_graph.png")
```
```{r loliAllTransitDist, echo=FALSE, message=FALSE, warning=FALSE, fig.align = "center", fig.cap="Percentage of population groups with access to any transit stops across Connecticut, based on reasonable distances for each mode."}
ct_transitAccessPops_df %>%
mutate(Group = recode(Group, "Minority" = "People of Color",
"No HS Dip" = "No HS Diploma")) %>%
ggplot(aes(x = reorder(Group,-PctAllTransit),
y = PctAllTransit)) +
geom_segment(aes(x = reorder(Group,-PctAllTransit), xend = reorder(Group,-PctAllTransit),
y = ct_transitAccessPops_df[1,8], yend = PctAllTransit),
color = "skyblue") +
geom_point(color = "blue", size = 4, alpha = 0.8) +
coord_flip() + xlab("") + ylab("") + ggtitle("Connecticut Populations with Access to\nany Transit Stops") + theme_light() +
theme(panel.grid.major.y = element_blank(),
panel.border = element_blank(),
axis.ticks.y = element_blank()) +
geom_text(aes(x = Group, y = PctAllTransit + 0.2 * sign(PctAllTransit),
label = paste0(round(PctAllTransit,0),"%")),
hjust = -0.2, vjust = -.4, size = 3,
color=rgb(100,100,100, maxColorValue=255)) +
scale_y_continuous(labels = function(x) paste0(x, "%")) +
geom_hline(yintercept = ct_transitAccessPops_df[1,8], linetype = "dashed") +
geom_text(aes(x = "Total Pop", y = 66, label = "Above state\naverage"),
color = "gray48") +
geom_text(aes(x = "Total Pop", y = 49, label = "Below state\naverage"),
color = "gray48") +
expand_limits(y = c(45,85))
ggsave("images/CT_Transit_graph.png")
```
Specific values of the same can be seen in Table \@ref(tab:statsTransitDist) below.
```{r statsTransitDist, echo=FALSE, message=FALSE, warning=FALSE, fig.align = "center", fig.cap="Connecticut populations living within 1/4 mile (400 meters) of a bus stop. Based on ACS 2018 Block Group data."}
# See table of distance by group
ct_transitAccessPops_df %>%
mutate(Group = recode(Group, "Minority" = "People of Color",
"No HS Dip" = "No HS Diploma")) %>%
mutate(PctBus = paste0(round(PctBus,1),"%"),
PctCommuter = paste0(round(PctCommuter,1),"%"),
PctAllTransit = paste0(round(PctAllTransit,1),"%")) %>%
kableExtra::kable(longtable = T, booktabs = T,
format.args = list(big.mark = ','), align = "r",
caption = "Populations with Access to Transit",
col.names = c("Group","CT Pop","Bus","Comm Rail","Any Transit","Bus","Comm Rail","Any Transit")) %>%
kableExtra::column_spec(3:8, width = "1.7cm") %>%
kableExtra::add_header_above(c(" " = 2, "Total Pop with Access" = 3, "Pct Pop with Access" = 3)) %>%
kableExtra::footnote(general = "Access is 1/4 mile (400m) from bus stop or 3 miles (4800m) from commuter rail stop.") %>%
kableExtra::kable_styling(latex_options = c("repeat_header","striped"))
```
The population percentages above provide a glimpse of average access to public transit across the state for different population groups. However, access also varies for specific communities. Indeed, it is important to consider vulnerable populations or transportation-limited populations that do not have reasonable access to transit.
```{r TransitNoAccess, include=FALSE}
BusNoAccess1 <- ct_blkgrps_sf_noBus %>%
st_centroid(.) %>%
st_intersection(ct_towns_sf,.) %>%
as.data.frame() %>%
left_join(., townpopsdf,by="NAME") %>%
group_by(NAME) %>%
summarize(`Block Groups` = n(),
`Over 64` = sum(NewOver64,na.rm = TRUE),
`Pct of Over 64` = round(sum(NewOver64)/max(TotalOver64)*100,1)) %>%
rename("City/Town" = NAME) %>%
mutate(`Pct of Over 64` = paste0(`Pct of Over 64`,"%")) %>%
arrange(desc(`Over 64`))
BusNoAccess2 <- ct_blkgrps_sf_noBus %>%
st_centroid(.) %>%
st_intersection(ct_towns_sf,.) %>%
as.data.frame() %>%
left_join(., townpopsdf,by="NAME") %>%
group_by(NAME) %>%
summarize(`Block Groups` = n(),
`Under 18` = sum(NewUnder18,na.rm = TRUE),
`Pct of Under 18` = round(sum(NewUnder18)/max(TotalUnder18)*100,1)) %>%
rename("City/Town" = NAME) %>%
mutate(`Pct of Under 18` = paste0(`Pct of Under 18`,"%")) %>%
arrange(desc(`Under 18`))
CommuterNoAccess1 <- ct_blkgrps_sf_noCR %>%
st_centroid(.) %>%