#' Title
#'
#' @param obtn_year
#' @param plot_width
#' @param plot_height
#'
#' @return
#' @export
#'
#' @examples
obtn_plot_largest_community <- function(obtn_year, plot_width = 5, plot_height = 3.8633, save_plot = TRUE) {
obtn_largest_community_sf <- obtn_largest_community %>%
dplyr::filter(year == obtn_year) %>%
dplyr::arrange(desc(population)) %>%
dplyr::mutate(n = dplyr::row_number()) %>%
dplyr::mutate(lat = dplyr::case_when(
geography == "Clackamas" ~ 45.4,
geography == "Washington" ~ 45.514415,
geography == "Multnomah" ~ 45.545634,
geography == "Polk" ~ 44.956786,
TRUE ~ lat
)) %>%
dplyr::mutate(long = dplyr::case_when(
geography == "Clackamas" ~ -122.703035,
geography == "Washington" ~ -122.82,
geography == "Multnomah" ~ -122.654335,
geography == "Polk" ~ -123.15,
TRUE ~ long
)) %>%
sf::st_as_sf(coords = c("long", "lat")) %>%
sf::st_set_crs(4269)
ggplot2::ggplot() +
ggplot2::geom_sf(data = obtn_boundaries_oregon_counties,
fill = tfff_light_green,
color = "white",
size = .5) +
ggplot2::geom_sf(data = obtn_largest_community_sf,
size = 6,
color = tfff_dark_green) +
ggplot2::geom_sf_text(data = obtn_largest_community_sf,
ggplot2::aes(label = n),
family = "Calibri",
fontface = "bold",
color = "white") +
ggplot2::coord_sf(datum = NA) +
ggplot2::scale_fill_manual(values = obtn_choropleth_colors) +
ggplot2::theme_void() +
ggplot2::theme(text = ggplot2::element_text(family = "Calibri",
size = 10),
legend.box.margin = ggplot2::margin(10,10,10,10),
legend.position = "bottom") +
ggplot2::scale_x_continuous(expand = c(0, 0)) +
ggplot2::scale_y_continuous(expand = c(0, 0)) +
ggplot2::labs(fill = NULL)
measure_to_plot_name <- "Largest Community"
if (save_plot == TRUE) {
obtn_save_plot(obtn_year, measure_to_plot_name, "Oregon", plot_width, plot_height)
}
ggplot2::last_plot()
}
#' Title
#'
#' @param obtn_year
#' @param plot_width
#' @param plot_height
#' @param save_plot
#'
#' @return
#' @export
#'
#' @examples
obtn_plot_largest_100_communities <- function(obtn_year, plot_width = 5, plot_height = 3.8633) {
plot <- oregon_largest_100_communities %>%
dplyr::slice_max(order_by = estimate, n = 100) %>%
dplyr::mutate(name = forcats::fct_reorder(name, estimate)) %>%
dplyr::mutate(name = forcats::fct_rev(name)) %>%
ggplot2::ggplot() +
ggplot2::geom_sf(data = obtn_boundaries_oregon_counties,
fill = tfff_light_gray,
color = "white",
size = .5) +
ggplot2::geom_sf(ggplot2::aes(size = estimate),
shape = 21,
fill = tfff_orange,
color = "white",
alpha = 0.5) +
ggplot2::theme_void() +
ggplot2::scale_size_continuous(range = c(1, 10),
breaks = c(10000, 100000, 250000, 500000)) +
ggplot2::theme(legend.position = "none")
plot
obtn_save_plot(obtn_year, "Largest 100 Communities", "Oregon", plot_width, plot_height)
plot
}
# obtn_plot_largest_100_communities(2022)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.