Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elipousson/ac4990ab2fcec9395f62855854f0ed6b to your computer and use it in GitHub Desktop.
Save elipousson/ac4990ab2fcec9395f62855854f0ed6b to your computer and use it in GitHub Desktop.
Script from July 2023, updated 2023-12-08.
library(getACS)
library(tidycensus)
commute_time <- tidycensus::get_acs(
geography = "county",
table = "B08136",
year = 2021,
survey = "acs5",
state = "MD",
cache = TRUE
)
c("B08136_002", "B08136_007", "B08136_011", "B08136_012")
c("B08134_011", "B08134_021", "B08134_031", "B08134_061")
travel_time <- tidycensus::get_acs(
geography = "county",
table = "B08134",
year = 2021,
survey = "acs5",
state = "MD",
cache = TRUE
) |>
getACS::label_acs_metadata()
# FIXME: This doesn't work with this geography
# allocation <- getACS::get_acs_tables(
# geography = "metropolitan/micropolitan statistical area",
# table = "B99084",
# year = 2021,
# survey = "acs5",
# cache = TRUE
# ) |>
# getACS::label_acs_metadata()
commute_time <- commute_time |>
getACS::label_acs_metadata()
commute_time_select <- commute_time |>
mutate(
NAME = str_remove(NAME, ", Maryland$"),
minutes = estimate
) |>
filter(indent == 1, NAME %in% mapbaltimore::baltimore_msa_counties$namelsad) |>
select(NAME, minutes, column_title)
travel_time_select <- travel_time |>
mutate(
NAME = str_remove(NAME, ", Maryland$")
)
travel_time_select |>
filter(
indent < 3
) |>
filter(NAME %in% mapbaltimore::baltimore_msa_counties$namelsad) |>
select_acs() |>
group_by(NAME) |>
getACS::gt_acs()
travel_time_select <- travel_time_select |>
filter(column_title %in% unique(commute_time_select$column_title)) |>
select(NAME, estimate, column_title)
combine_travel_time <- commute_time_select |>
left_join(travel_time_select) |>
mutate(
means = column_title,
minutes = dminutes(minutes / estimate)
)
avg_travel_by_means <- combine_travel_time |>
summarise(
minutes = mean(minutes),
.by = means
)
combine_travel_time |>
ggplot(aes(color = NAME, x = minutes, y = means)) +
geom_point(
size = 5,
alpha = 0.8
) +
# geom_point(
# data = avg_travel_by_means,
# aes(x = minutes, y = means)
# ) +
# geom_hline(aes(yintecept = mean(minutes))) +
# stat_summary(
# aes(group = column_title), fun = mean, geom = "point",
# colour="black",
# size = 7
# ) +
scale_x_time() +
# maplayer::theme_legend("topright", inset = TRUE) +
pilot::theme_pilot() +
labs(
y = "Means of transportation",
x = "Average travel time (minutes)"
)
# FIXME
# - Axis titles too small
# - Needs a title
# - Legend not working
# - Annotations with averages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment