R/obtn_plot_alice_map.R

Defines functions obtn_plot_alice_map

Documented in obtn_plot_alice_map

#' Make map of ALICE thresholds in counties throughout Oregon
#'
#' @param obtn_year
#'
#' @return
#' @export
#'
#' @examples
obtn_plot_alice_map <- function(obtn_year) {

  obtn_alice_data_thresholds_geospatial <- obtn_alice_data_thresholds %>%
    dplyr::filter(year == obtn_year) %>%
    dplyr::mutate(value_categorical = scales::dollar(value,
                                                     accuracy = 1)) %>%
    dplyr::mutate(age = forcats::fct_rev(age)) %>%
    dplyr::left_join(obtn_boundaries_oregon_counties,
                     by = "geography") %>%
    sf::st_as_sf()

  obtn_alice_data_thresholds_geospatial %>%
    ggplot2::ggplot() +
    ggplot2::geom_sf(data = obtn_boundaries_oregon_counties,
                     color = "white",
                     fill = tfff_light_gray,
                     size = .25) +
    ggplot2::geom_sf(color = "white",
                     fill = tfff_dark_green,
                     size = .25) +
    ggplot2::coord_sf(datum = NA) +
    ggplot2::theme_void() +
    # ggplot2::labs(title = age_to_filter) +
    ggplot2::theme(text = ggplot2::element_text(family = "Calibri",
                                                size = 10),
                   # strip.text = ggplot2::element_blank(),
                   plot.title = ggplot2::element_text(family = "Calibri",
                                                      face = "bold",
                                                      hjust = 0.5,
                                                      size = 11,
                                                      margin = ggplot2::margin(b = 10, unit = "pt"))) +
    ggplot2::labs(fill = NULL) +
    ggplot2::facet_grid(rows = ggplot2::vars(value_categorical),
                        cols = ggplot2::vars(age))

  ggplot2::ggsave(filename = stringr::str_glue("inst/plots/{obtn_year}/{obtn_year}-alice-threshold-maps.pdf"),
                  device = cairo_pdf)

}
rfortherestofus/obtn documentation built on Nov. 13, 2022, 7:25 p.m.