obtn_plot_alice_threshold_single_age <- function(obtn_year, age_to_filter) {
obtn_alice_data_thresholds_filtered <-
obtn_alice_data_thresholds |>
dplyr::filter(year == obtn_year) |>
dplyr::filter(age == age_to_filter) |>
dplyr::mutate(value_formatted = scales::dollar(value, accuracy = 1)) %>%
dplyr::mutate(age = forcats::fct_rev(age)) |>
dplyr::mutate(geography = forcats::fct_rev(geography)) %>%
# dplyr::mutate(
# value_formatted = scales::number(
# value,
# accuracy = 0.1,
# prefix = "$"
# ,
# scale_cut = scales::cut_long_scale()
# )
# ) |>
dplyr::mutate(geography = forcats::fct_reorder(geography, value)) |>
dplyr::mutate(value_formatted = scales::dollar(value, accuracy = 1)) %>%
dplyr::mutate(age = forcats::fct_rev(age)) |>
dplyr::mutate(geography = forcats::fct_rev(geography)) %>%
# dplyr::mutate(
# value_formatted = scales::number(
# value,
# accuracy = 0.1,
# prefix = "$",
# scale_cut = scales::cut_long_scale()
# )
# ) |>
dplyr::mutate(geography = forcats::fct_reorder(geography, value))
obtn_alice_data_thresholds_filtered |>
ggplot2::ggplot(ggplot2::aes(x = value, y = geography)) +
ggplot2::geom_col(fill = tfff_light_gray, width = 0.85, ggplot2::aes(x = max(
obtn_alice_data_thresholds_filtered$value
))) +
ggplot2::geom_col(fill = tfff_light_green, width = 0.85) +
ggplot2::geom_text(
ggplot2::aes(label = value_formatted),
hjust = 1.1,
size = 3.25,
color = "black",
family = "ProximaNova-Regular"
) +
ggplot2::scale_x_continuous(
limits = c(0, max(
obtn_alice_data_thresholds_filtered$value
)),
breaks = seq(0, max(
obtn_alice_data_thresholds_filtered$value
), 25000),
expand = ggplot2::expansion(0, 0)
) +
ggplot2::facet_grid(cols = ggplot2::vars(age)) +
ggplot2::theme_void(base_family = "ProximaNova-Regular") +
ggplot2::theme(
axis.text.y = ggplot2::element_text(hjust = 0, margin = ggplot2::margin(r = 10)),
strip.text = ggplot2::element_text(
size = 12,
margin = ggplot2::margin(b = 5),
family = "ProximaNova-Bold"
),
plot.margin = ggplot2::margin(10, 10, 10, 10)
)
}
#' Make ALICE threshold plot
#'
#' @param obtn_year
#'
#' @return
#' @export
#'
#' @examples
obtn_plot_alice_threshold <- function(obtn_year) {
obtn_plot_alice_threshold_single_age(obtn_year, "Under 65") +
obtn_plot_alice_threshold_single_age(obtn_year, "65 and older")
ggplot2::ggsave(
filename = stringr::str_glue(
"inst/plots/{obtn_year}/{obtn_year}-alice-threshold-plot.pdf"
),
width = 7.5,
height = 10,
device = cairo_pdf
)
}
# obtn_plot_alice_threshold(2024)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.