Last active
September 26, 2022 04:54
-
-
Save stephhazlitt/aefe1ef492e6fa8c26e51ee394ae82a8 to your computer and use it in GitHub Desktop.
popn-estimates-projections-by-sd-crd-plot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(here) | |
library(readr) | |
library(dplyr) | |
library(ggplot2) | |
library(scales) | |
library(ggrepel) | |
## Data for School District 61 Population Estimates & Projections from BCStats | |
## manual online tool: https://bcstats.shinyapps.io/popApp/ | |
sd61_kids <- read_csv(here("Population_Projections.csv")) |> | |
mutate(data_type = case_when(Year < 2022 ~ "estimated", | |
TRUE ~ "projected")) |> | |
janitor::clean_names() | |
#plot of population estimates by SD | |
sd61_kids_plot <- sd61_kids |> | |
mutate(label = if_else( | |
year == 2028, | |
as.character(school_district), | |
NA_character_ | |
)) |> | |
ggplot() + | |
geom_line(aes(year, total, | |
group = school_district, | |
colour = data_type), | |
size = 1) + | |
labs(title = "Population Estimates & Projections by School District", | |
caption = "Data sourced from BC Stats", | |
x = NULL, y = NULL) + | |
scale_x_continuous( | |
limits = c(1986, 2041), | |
breaks = seq(1986, 2041, 6), | |
expand = c(0, 0) | |
) + | |
scale_y_continuous( | |
limits = c(40000, 310000), | |
breaks = seq(40000, 310000, 20000), | |
expand = c(0, 0), | |
labels = scales::comma | |
) + | |
scale_colour_manual(name = "", | |
values = c("#034e7b", | |
"#d0d1e6")) + | |
theme_minimal() + | |
geom_label( | |
aes(year, total, | |
group = school_district, | |
label = label), | |
# nudge_x = -15, | |
na.rm = TRUE | |
) | |
ggsave("crd-popn-by-sd.png", | |
device = "png", | |
sd61_kids_plot, | |
dpi = 300, | |
bg = "white") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment