cond <- c("OBJECTID_12", "Route", "Stop_ID", "Avg_POPDENS_CY", "Avg_AVGHHSZ_CY", "Avg_MEDAGE_CY", "Avg_MALES_CY",
"Avg_FEMALES_CY", "Avg_UNEMPRT_CY", "Avg_WHITE_CY",
"Avg_BLACK_CY", "Avg_ASIAN_CY", "Avg_HISPPOP_CY",
"Avg_MEDHINC_CY", "Weekday_Bo", "Weekday_Le", "Weekday_To", "Distance", "Avg_TOTPOP_CY")
c1 <- c %>%
dplyr::select(.,cond) %>%
cleanup.import() ##cleans data and converts to integer when needed
cn <- c1 %>%
dplyr::rename(`ID`= OBJECTID_12,
`Route` = Route,
`Stop Number` = Stop_ID,
`Population Density` = Avg_POPDENS_CY,
`Household Size` = Avg_AVGHHSZ_CY,
`Age` = Avg_MEDAGE_CY,
`Male Population` = Avg_MALES_CY,
`Female Population` = Avg_FEMALES_CY,
`Unemployment Rate` = Avg_UNEMPRT_CY,
`White Population` = Avg_WHITE_CY,
`Black Population` = Avg_BLACK_CY,
`Asian Population` = Avg_ASIAN_CY,
`Hispanic Population` = Avg_HISPPOP_CY,
`Median HH Income` = Avg_MEDHINC_CY,
`Boardings` = Weekday_Bo,
`Offsets` = Weekday_Le,
`Total Riders` = Weekday_To,
`Distance` = Distance,
`Total Population` = Avg_TOTPOP_CY)
cn <- cn %>%
mutate(
Black= (`Black Population` / `Total Population`* 100),
Asian= (`Asian Population` / `Total Population`* 100),
Hispanic= (`Hispanic Population` / `Total Population`* 100),
White= (`White Population` / `Total Population`* 100),
Female = (`Female Population` / `Total Population` * 100),
`City Hall` = ifelse( `Stop Number` == 6115|`Stop Number`== 130|`Stop Number`== 17261|`Stop Number`== 5131, 1, 0))
exp_vars <- c("Population Density", "Household Size", "Age", "Female",
"Unemployment Rate", "White",
"Black", "Asian", "Hispanic", "City Hall",
"Median HH Income", "Boardings", "Distance")
mpd <- c("OBJECTID_12", "Weekday_Bo", "Route", "Latitude", "Longitude")
c1_16 <- cn %>%
mutate(
ID = ifelse(Route == 16, ID, NA)) %>%
filter(!is.na(ID)
)
c1_21 <- cn %>%
mutate(
ID = ifelse(Route == 21, ID, NA),
Boardings = ifelse(Boardings == 0, 1, Boardings)) %>%
filter(!is.na(ID)
)
c2_21 <- c1 %>%
mutate(
ID = ifelse(Route == 21, OBJECTID_12, NA)) %>%
filter(!is.na(OBJECTID_12)
)
c2_16 <- c1 %>%
mutate(
ID = ifelse(Route == 16, OBJECTID_12, NA)) %>%
filter(!is.na(OBJECTID_12)
)
kable(head(c1_21 %>% dplyr::select(exp_vars), 10),
col.names = c("Population Density", "Household Size", "Median Age", "Male Population",
"Female Population", "Unemployment Rate",
"White Population", "Black Population", "Asian Population",
"Hispanic Population", "Median Household Income", "Ridership",
"Distance")) %>%
kable_styling(bootstrap_options = "striped",position = "left") %>%
scroll_box(width = "100%", height = "100%")
map1 <- tm_shape(dat_sf, unit = "mi", bbox = boundingBox) +
tm_dots(title.size = "Bus Stops", alpha = 0.5, size = "Weekday_Bo", col = "Weekday_Bo", title = "Ridership") +
tm_shape(busroutes) +
tm_lines(col = "#CE8F98", scale = .35)+
tm_layout(main.title = "Bus Lines",
asp = 0, legend.outside = TRUE, legend.outside.position = "bottom",
title.snap.to.legend = FALSE, title.position = c("center", "top"),
outer.margins = c(0, 0, 0, 0),
inner.margins = c(0, 0, 0, 0)) +
tm_shape(boundingBox) +
tm_borders() +
tm_layout(main.title = "Route 21 and 16 Bus Routes",
asp = 0, legend.outside = TRUE, legend.outside.position = "bottom",
title.snap.to.legend = FALSE, title.position = c("center", "top"),
outer.margins = c(0, 0, 0, 0),
inner.margins = c(0, 0, 0, 0))
map1