Skip to content

Instantly share code, notes, and snippets.

@elipousson
Last active September 30, 2023 21:30
Show Gist options
  • Select an option

  • Save elipousson/12fb5fa306a5466d0fb95ec90536c4a6 to your computer and use it in GitHub Desktop.

Select an option

Save elipousson/12fb5fa306a5466d0fb95ec90536c4a6 to your computer and use it in GitHub Desktop.
A R script to reproduce a graphic map created to visualize the distribution of elementary and elementary/middle school households surveyed in 2019 who responded to the question, "How does your child usually walk to school?" with "Walking".
# pak::pkg_install(c("elipousson/bcpss", "elipousson/mapbaltimore", "elipousson/maplayer", "hrbrthemes"))
library(bcpss)
library(tidyverse)
library(sf)
transportation_survey_resp <- parent_survey_SY1819 |>
select(
starts_with("school_n"),
c("grade_band", "management_type", "parent_response_count"),
starts_with("est_"),
starts_with("transportation_")
) |>
pivot_longer(
cols = starts_with("transportation")
)
transportation_survey_resp |>
filter(
grade_band %in% c("E", "EM"),
name == "transportation_how_does_your_child_usually_get_to_school_walk"
) |>
left_join(
y = sf::st_drop_geometry(bcpss::bcps_es_zones_SY2021),
by = join_by(school_number == zone_number)
) |>
left_join(
bcpss::bcps_es_zones_SY2021 |>
select(school_number = zone_number)
) |>
sf::st_as_sf() |>
# sfext::st_erase(
# mapbaltimore::baltimore_water
# ) |>
# sfext::st_erase(
# mapbaltimore::parks
# ) |>
ggplot() +
geom_sf(
aes(fill = value),
linewidth = 0.1,
color = "gray95"
) +
geom_sf(
data = mapbaltimore::baltimore_water,
fill = "lightblue",
color = NA, #"lightblue",
alpha = 0.8
) +
geom_sf(
data = mapbaltimore::parks |>
filter(acres > units::set_units(10, "acres")),
fill = "lightgreen",
color = NA, # "white",
linewidth = 0.5,
alpha = 0.6
) +
geom_sf(
data = mapbaltimore::baltimore_city,
color = "white",
fill = NA
) +
scale_fill_continuous(label = scales::percent) +
labs(
title = 'Asking parents and guardians:\n"How does your child usually get to school?"',
subtitle = "Share of total responses by BCPSS Elementary School Attendance Zones",
fill = '% "Walking"',
caption = "Source: 2019 BCPSS Parent Survey Data; BCPSS ES Attendance Zones SY20"
) +
# baltimoreplanning::theme_baltimoreplanning(
# axis_text_size = 0,
# legend_position = "right"
# ) +
hrbrthemes::theme_ipsum_pub(
axis_text_size = 0
) +
maplayer:::theme_grid() +
# maplayer:::theme_background() +
# maplayer:::theme_sf_axes() +
ggplot2::theme(
legend.key.size = unit(50, "pt")#,
# legend.justification = "right"
)
# baltimoreplanning::ggsave_last_plot(
# ggsave_params = list(
# filename = "parent_survey_SY1819_transportation-walking.png",
# width = 1400,
# height = 1400,
# scale = 2,
# bgcolor = "white",
# unit = "px"
# )
# )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment