Skip to content

Instantly share code, notes, and snippets.

@dhersz
Created February 17, 2023 20:22
Show Gist options
  • Save dhersz/3271d60c474cfd694dde5157f5eb5615 to your computer and use it in GitHub Desktop.
Save dhersz/3271d60c474cfd694dde5157f5eb5615 to your computer and use it in GitHub Desktop.
library(accessibility)
library(ggplot2)
data_dir <- system.file("extdata", package = "accessibility")
travel_matrix <- readRDS(file.path(data_dir, "travel_matrix.rds"))
land_use_data <- readRDS(file.path(data_dir, "land_use_data.rds"))
access <- cumulative_cutoff(
travel_matrix,
land_use_data,
cutoff = 1:120,
opportunity = "jobs",
travel_cost = "travel_time"
)
access
# ideally we'd have to weigh by each origin population here, but you get the
# point
avg_access <- access[, .(avg_access = mean(jobs)), by = cutoff]
total_jobs <- sum(land_use_data$jobs)
ggplot(avg_access) +
geom_line(aes(cutoff, avg_access)) +
scale_y_continuous(
labels = scales::label_percent(scale = 100 / total_jobs)
) +
labs(
x = "Travel time cutoff",
y = "Avg. accessibility\n(% of total jobs in the study area)"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment