From d8e91598e4f842a9c3954d81cb7399de80ca385b Mon Sep 17 00:00:00 2001 From: ehesch Date: Thu, 4 Aug 2022 08:18:14 -0500 Subject: [PATCH 01/13] add example to fetch_county_geo --- R/fetch_county_geo.R | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/R/fetch_county_geo.R b/R/fetch_county_geo.R index 3e601dd..a90ccac 100644 --- a/R/fetch_county_geo.R +++ b/R/fetch_county_geo.R @@ -18,6 +18,17 @@ #' @importFrom cli cli_abort #' @importFrom purrr map #' +#' @examples +#' \dontrun{ +# library(ggplot2) +# library(councilR) +# +# fetch_county_geo() %>% +# ggplot() + +# geom_sf() + +# theme_void() +#'} + fetch_county_geo <- function(core = TRUE, ...) { rlang:::check_bool(core) From d25859b65f8e267bf3f8dd3a9115f4fd60c0d490 Mon Sep 17 00:00:00 2001 From: ehesch Date: Thu, 4 Aug 2022 08:18:40 -0500 Subject: [PATCH 02/13] fix typo --- vignettes/Spatial_helpers.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/Spatial_helpers.Rmd b/vignettes/Spatial_helpers.Rmd index 374b5f3..5e6a6fa 100644 --- a/vignettes/Spatial_helpers.Rmd +++ b/vignettes/Spatial_helpers.Rmd @@ -59,7 +59,7 @@ regional_parks_db <- import_from_gis(query = "PARKSREGIONAL") head(regional_parks_db) ``` -A commonly fetch spatial dataset is the 7-county geography. `fetch_county_geo()` does just that. +A commonly fetched spatial dataset is the 7-county geography. `fetch_county_geo()` does just that. ```{r, eval = FALSE} fetch_county_geo() From d12e94a3953266916a888889980b70d02ca6f6d9 Mon Sep 17 00:00:00 2001 From: ehesch Date: Thu, 20 Oct 2022 15:50:12 -0500 Subject: [PATCH 03/13] Update fetch_county_geo.R add a function fetch_ctu_geo() --- R/fetch_county_geo.R | 90 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 3 deletions(-) diff --git a/R/fetch_county_geo.R b/R/fetch_county_geo.R index a90ccac..5e1708b 100644 --- a/R/fetch_county_geo.R +++ b/R/fetch_county_geo.R @@ -1,15 +1,29 @@ -#' @title Fetch standardized county geography +#' @title Fetch standardized geographies +#' +#' @description The default `fetch_county_geo()` to return county outlines, plus a suite of other functions to return more niche geographies. +#' +#'To get city, township, and unorganized territory (CTU) boundaries, use `fetch_ctu_geo()`. #' #' @param core logical, whether to include all counties in the MPO. #' Default is `TRUE`. -#' @param ... Arguments passed to `[tigris::counties]` +#' @param ... Arguments passed to `[tigris]` functions #' -#' @return An [`sf`] object containing county geographies. +#' @return An [`sf`] object containing specified geographies. #' @export #' @family spatial helpers #' @examples #' \dontrun{ #' fetch_county_geo() +#' +#' library(ggplot2) +#' fetch_ctu_geo() %>% +#' ggplot() + +#' geom_sf(fill = "grey90") + +#' theme_void() + +#' geom_sf_text(aes(label = CTU_NAME), +#' colour = "black", +#' check_overlap = F, +#' size = 2) #' } #' #' @note This function relies on `[{rlang}]` internal functions. @@ -64,3 +78,73 @@ fetch_county_geo <- function(core = TRUE, ...) { return(county_sf) } + +#' @rdname fetch_county_geo +#' @export +#' + +fetch_ctu_geo <- function(core = TRUE, ...) { + rlang:::check_bool(core) + + county_list <- if (core == TRUE) { + c( + "Anoka", + "Carver", + "Dakota", + "Hennepin", + "Ramsey", + "Scott", + "Washington" + ) + } else if (core == FALSE) { + c( + "Anoka", + "Carver", + "Dakota", + "Hennepin", + "Ramsey", + "Scott", + "Sherburne", + "Washington", + "Wright" + ) + } + + cities <- tigris::county_subdivisions( + state = "MN", + county = county_list, + class = "sf" + ) %>% + dplyr::mutate(NAME = dplyr::case_when( + LSAD == 44 ~ paste(NAME, "Twp."), + LSAD == 46 ~ paste(NAME, "(unorg.)"), + TRUE ~ NAME + )) %>% + ## if expanding to greater mn or another region, you do have to do some unions, and further cleaning. + # group_by(NAME) %>% + # mutate(n = n()) %>% + # left_join(st_drop_geometry(county_outline) %>% + # transmute( + # COUNTYFP = COUNTYFP, + # CONAME = NAME + # )) %>% + # mutate(NAME = case_when( + # n > 1 & LSAD != 25 ~ paste0(NAME, " - ", CONAME, " Co."), # cities dont get merged + # TRUE ~ NAME + # )) %>% + # group_by(NAME) %>% + # summarise() %>% + # # summarize(geometry = st_union(geom)) %>% + # arrange(NAME) %>% + # rename(GEO_NAME = NAME) + dplyr::transmute(CTU_NAME = NAME) + + + return(cities) +} + + +#' @rdname fetch_ctu_geo +#' @export +#' + From db613bb8d7fbec2647ac1e6986aae02810e90dd0 Mon Sep 17 00:00:00 2001 From: ehesch Date: Thu, 20 Oct 2022 18:55:57 -0500 Subject: [PATCH 04/13] add theme_council_geo() --- R/theme_council.R | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/R/theme_council.R b/R/theme_council.R index b4f1b26..0f2167f 100644 --- a/R/theme_council.R +++ b/R/theme_council.R @@ -1,6 +1,6 @@ #' @title Council ggplot2 theme #' -#' @description The default `theme_council()` plus a more simple `theme_council_open()` for making MetCouncil figures. `theme_council()` will be appropriate in most cases while `theme_council_open()` is appropriate for single scatter plots or line graphs. +#' @description The default `theme_council()` plus a more simple `theme_council_open()` for making MetCouncil figures. `theme_council()` will be appropriate in most cases while `theme_council_open()` is appropriate for single scatter plots or line graphs. For geospatial plots, `theme_council_geo()` may be useful to set some initial parameters. #' #' Please note that the y-axis text is horizontal, and long axis names will need to be wrapped; [`stringr::str_wrap()`]() is useful for managing length. #' For example, consider using this piece of code: `labs(y = stringr::str_wrap("Axis labels are now horizontal, but you still need to insert some code to wrap long labels", width = 15))` @@ -80,9 +80,14 @@ #' use_showtext = TRUE, #' use_manual_font_sizes = TRUE #' ) +#' +#' fetch_ctu_geo() %>% +#' ggplot() + +#' geom_sf() + +#' theme_council_geo() #' } #' -#' @importFrom ggplot2 theme element_text element_blank element_rect element_line margin unit rel %+replace% +#' @importFrom ggplot2 theme element_text element_blank element_rect element_line margin unit rel %+replace% theme_void #' @importFrom purrr map #' #' @@ -449,6 +454,22 @@ theme_council_open <- function(base_size = 11, ) } -#' @rdname theme_council_open +#' @rdname theme_council +#' @export +#' +theme_council_geo <- function() { + # Starts with theme_void and then modifies some parts + + ggplot2::`%+replace%`( + theme_void(), + ggplot2::theme( + legend.title = element_text(size = 6), + legend.text = element_text(size = 6), + legend.key.size = unit(.75, "lines") + ) + ) +} + +#' @rdname theme_council #' @export #' From 656aa00dff85efd7d55301c75c09b050fc6d65f9 Mon Sep 17 00:00:00 2001 From: ehesch Date: Thu, 20 Oct 2022 18:56:29 -0500 Subject: [PATCH 05/13] add fetch_ctu_geo() function --- R/fetch_county_geo.R | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/R/fetch_county_geo.R b/R/fetch_county_geo.R index 5e1708b..ea458f2 100644 --- a/R/fetch_county_geo.R +++ b/R/fetch_county_geo.R @@ -13,10 +13,14 @@ #' @family spatial helpers #' @examples #' \dontrun{ -#' fetch_county_geo() -#' #' library(ggplot2) -#' fetch_ctu_geo() %>% +#' +#' fetch_county_geo() %>% +# ggplot() + +# geom_sf() + +# theme_void() +#' +#'fetch_ctu_geo() %>% #' ggplot() + #' geom_sf(fill = "grey90") + #' theme_void() + @@ -31,17 +35,9 @@ #' @importFrom tigris counties #' @importFrom cli cli_abort #' @importFrom purrr map +#' @importFrom dplyr case_when mutate transmute #' -#' @examples -#' \dontrun{ -# library(ggplot2) -# library(councilR) -# -# fetch_county_geo() %>% -# ggplot() + -# geom_sf() + -# theme_void() -#'} + fetch_county_geo <- function(core = TRUE, ...) { rlang:::check_bool(core) @@ -85,6 +81,7 @@ fetch_county_geo <- function(core = TRUE, ...) { fetch_ctu_geo <- function(core = TRUE, ...) { rlang:::check_bool(core) + NAME <- CTU_NAME <- ALAND <- AWATER <- NULL county_list <- if (core == TRUE) { c( @@ -115,7 +112,7 @@ fetch_ctu_geo <- function(core = TRUE, ...) { county = county_list, class = "sf" ) %>% - dplyr::mutate(NAME = dplyr::case_when( + mutate(NAME = case_when( LSAD == 44 ~ paste(NAME, "Twp."), LSAD == 46 ~ paste(NAME, "(unorg.)"), TRUE ~ NAME @@ -137,7 +134,9 @@ fetch_ctu_geo <- function(core = TRUE, ...) { # # summarize(geometry = st_union(geom)) %>% # arrange(NAME) %>% # rename(GEO_NAME = NAME) - dplyr::transmute(CTU_NAME = NAME) + transmute(CTU_NAME = NAME, + ALAND = ALAND, + AWATER = AWATER) return(cities) From 8b0eed0a90e4632cdc778febcb3ee0f5c799d6e0 Mon Sep 17 00:00:00 2001 From: ehesch Date: Thu, 20 Oct 2022 18:56:49 -0500 Subject: [PATCH 06/13] create mapping function; map_council_continuous() --- R/map_council.R | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 R/map_council.R diff --git a/R/map_council.R b/R/map_council.R new file mode 100644 index 0000000..ad11ac4 --- /dev/null +++ b/R/map_council.R @@ -0,0 +1,63 @@ +#' @title Council map starters +#' +#' @description Building on functionality for creating maps When mapping continuous data, `map_council_continuous()` could save some work. +#' +#'@param df The `sf` object to be mapped +#' @param .fill For continuous data, the variable which should be used to fill polygons +#' @param .lwd The line width of polygons, default setting is `0.5`. +#' @param .low The color to fill the lowest number. Default is brown. +#' @param .mid The color to fill the midpoint number. Default is white +#' @param .high The color to fill the highest number. Default is teal +#' @param .midpoint The midpoint of a diverging color scheme. Default is `0`. +#' +#' @return a [ggplot2] plot +#' @export +#' +#' @family aesthetics +#' +#' @note This function relies on `[{rlang}]` internal functions. +#' +#' @examples +#' \dontrun{ +#' library(ggplot2) +#' library(councilR) +#' +#' fetch_ctu_geo() %>% +#' map_council_continuous(.fill = ALAND, .midpoint = 5e7) +#' +#' } +#' +#' @importFrom ggplot2 ggplot geom_sf scale_fill_gradient2 aes +#' @importFrom ggspatial annotation_north_arrow north_arrow_fancy_orienteering annotation_scale +#' @importFrom rlang enquo +#' + +map_council_continuous <- function(df, + .fill, + .lwd = .5, + .low = "#8c510a", + .mid = "white", + .high = "#01665e", + .midpoint = 0){ + df %>% + ggplot()+ + geom_sf(aes(fill = !!enquo(.fill)), lwd = .lwd) + + theme_council_geo() + + scale_fill_gradient2(low = .low, mid = .mid, high = .high, midpoint = .midpoint) + + annotation_scale( + location = "bl", + bar_cols = c("grey60", "white") + ) + + annotation_north_arrow( + location = "tr", which_north = "true", + # pad_x = unit(0.4, "in"), pad_y = unit(0.4, "in"), + style = north_arrow_fancy_orienteering( + fill = c("grey40"), + line_col = "grey20" + )) +} + +#' @rdname map_council_continuous +#' @export +#' + From e433b6cf56b551beff186b37c736f5a97c5c90a7 Mon Sep 17 00:00:00 2001 From: ehesch Date: Thu, 20 Oct 2022 18:56:57 -0500 Subject: [PATCH 07/13] Update DESCRIPTION --- DESCRIPTION | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 391ce7e..3c3f549 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Type: Package Package: councilR Title: Functions and Templates for the Metropolitan Council Version: 0.1.3 -Date: 2022-08-01 +Date: 2022-10-20 Authors@R: c( person("Metropolitan Council", role = "cph"), person("Liz", "Roten", , "liz.roten@metc.state.mn.us", role = c("cre", "aut"), @@ -33,7 +33,9 @@ Imports: sf (>= 0.9.5), tictoc (>= 1.0), tigris (>= 1.6.1), - utils + utils, + ggspatial (>= 1.1.6), + dplyr (>= 1.0.10) Suggests: citr (>= 0.3.2), cowplot (>= 1.1.1), From a21dfb91944dc644afed22bcac405b7226ba16bd Mon Sep 17 00:00:00 2001 From: ehesch Date: Thu, 20 Oct 2022 18:57:41 -0500 Subject: [PATCH 08/13] styler --- R/blue_cascade.R | 2 +- R/fetch_county_geo.R | 68 +++++++++++++++++++++++--------------------- R/import_from_gis.R | 2 +- R/map_council.R | 13 ++++----- R/theme_council.R | 2 +- 5 files changed, 44 insertions(+), 43 deletions(-) diff --git a/R/blue_cascade.R b/R/blue_cascade.R index 4fb2b62..d3560ab 100644 --- a/R/blue_cascade.R +++ b/R/blue_cascade.R @@ -2,7 +2,7 @@ #' #' @description A named list of background and text colors for cascading menus #' -#' @format A named list of 8 lists. Each item contains a named list +#' @format A named list of 8 lists. Each item contains a named list #' of two items: #' - "background" is the background or fill color #' - "color" is the text or contrast color diff --git a/R/fetch_county_geo.R b/R/fetch_county_geo.R index ea458f2..55b3b20 100644 --- a/R/fetch_county_geo.R +++ b/R/fetch_county_geo.R @@ -2,7 +2,7 @@ #' #' @description The default `fetch_county_geo()` to return county outlines, plus a suite of other functions to return more niche geographies. #' -#'To get city, township, and unorganized territory (CTU) boundaries, use `fetch_ctu_geo()`. +#' To get city, township, and unorganized territory (CTU) boundaries, use `fetch_ctu_geo()`. #' #' @param core logical, whether to include all counties in the MPO. #' Default is `TRUE`. @@ -16,18 +16,19 @@ #' library(ggplot2) #' #' fetch_county_geo() %>% -# ggplot() + -# geom_sf() + -# theme_void() +#' # ggplot() + +#' # geom_sf() + +#' # theme_void() #' -#'fetch_ctu_geo() %>% -#' ggplot() + -#' geom_sf(fill = "grey90") + -#' theme_void() + -#' geom_sf_text(aes(label = CTU_NAME), -#' colour = "black", -#' check_overlap = F, -#' size = 2) +#' fetch_ctu_geo() %>% +#' ggplot() + +#' geom_sf(fill = "grey90") + +#' theme_void() + +#' geom_sf_text(aes(label = CTU_NAME), +#' colour = "black", +#' check_overlap = F, +#' size = 2 +#' ) #' } #' #' @note This function relies on `[{rlang}]` internal functions. @@ -117,26 +118,28 @@ fetch_ctu_geo <- function(core = TRUE, ...) { LSAD == 46 ~ paste(NAME, "(unorg.)"), TRUE ~ NAME )) %>% - ## if expanding to greater mn or another region, you do have to do some unions, and further cleaning. - # group_by(NAME) %>% - # mutate(n = n()) %>% - # left_join(st_drop_geometry(county_outline) %>% - # transmute( - # COUNTYFP = COUNTYFP, - # CONAME = NAME - # )) %>% - # mutate(NAME = case_when( - # n > 1 & LSAD != 25 ~ paste0(NAME, " - ", CONAME, " Co."), # cities dont get merged - # TRUE ~ NAME - # )) %>% - # group_by(NAME) %>% - # summarise() %>% - # # summarize(geometry = st_union(geom)) %>% - # arrange(NAME) %>% - # rename(GEO_NAME = NAME) - transmute(CTU_NAME = NAME, - ALAND = ALAND, - AWATER = AWATER) + ## if expanding to greater mn or another region, you do have to do some unions, and further cleaning. + # group_by(NAME) %>% + # mutate(n = n()) %>% + # left_join(st_drop_geometry(county_outline) %>% + # transmute( + # COUNTYFP = COUNTYFP, + # CONAME = NAME + # )) %>% + # mutate(NAME = case_when( + # n > 1 & LSAD != 25 ~ paste0(NAME, " - ", CONAME, " Co."), # cities dont get merged + # TRUE ~ NAME + # )) %>% + # group_by(NAME) %>% + # summarise() %>% + # # summarize(geometry = st_union(geom)) %>% + # arrange(NAME) %>% + # rename(GEO_NAME = NAME) + transmute( + CTU_NAME = NAME, + ALAND = ALAND, + AWATER = AWATER + ) return(cities) @@ -146,4 +149,3 @@ fetch_ctu_geo <- function(core = TRUE, ...) { #' @rdname fetch_ctu_geo #' @export #' - diff --git a/R/import_from_gis.R b/R/import_from_gis.R index 928dfe6..d628cb7 100644 --- a/R/import_from_gis.R +++ b/R/import_from_gis.R @@ -9,7 +9,7 @@ #' @note See `vignette("Options")` to review package options. #' You must be set up with the appropriate database drivers #' to use this function. -#' **Windows** users need ODBC with Microsoft SQL. +#' **Windows** users need ODBC with Microsoft SQL. #' Contact IS support for ODBC installation. #' **Mac** users need `unixodbc` and `freetds`. #' See instructions in the [onboarding guide](https://furry-adventure-596f3adb.pages.github.io/database-connections.html) diff --git a/R/map_council.R b/R/map_council.R index ad11ac4..18cbff7 100644 --- a/R/map_council.R +++ b/R/map_council.R @@ -2,7 +2,7 @@ #' #' @description Building on functionality for creating maps When mapping continuous data, `map_council_continuous()` could save some work. #' -#'@param df The `sf` object to be mapped +#' @param df The `sf` object to be mapped #' @param .fill For continuous data, the variable which should be used to fill polygons #' @param .lwd The line width of polygons, default setting is `0.5`. #' @param .low The color to fill the lowest number. Default is brown. @@ -23,8 +23,7 @@ #' library(councilR) #' #' fetch_ctu_geo() %>% -#' map_council_continuous(.fill = ALAND, .midpoint = 5e7) -#' +#' map_council_continuous(.fill = ALAND, .midpoint = 5e7) #' } #' #' @importFrom ggplot2 ggplot geom_sf scale_fill_gradient2 aes @@ -38,9 +37,9 @@ map_council_continuous <- function(df, .low = "#8c510a", .mid = "white", .high = "#01665e", - .midpoint = 0){ + .midpoint = 0) { df %>% - ggplot()+ + ggplot() + geom_sf(aes(fill = !!enquo(.fill)), lwd = .lwd) + theme_council_geo() + scale_fill_gradient2(low = .low, mid = .mid, high = .high, midpoint = .midpoint) + @@ -54,10 +53,10 @@ map_council_continuous <- function(df, style = north_arrow_fancy_orienteering( fill = c("grey40"), line_col = "grey20" - )) + ) + ) } #' @rdname map_council_continuous #' @export #' - diff --git a/R/theme_council.R b/R/theme_council.R index 0f2167f..678e0e9 100644 --- a/R/theme_council.R +++ b/R/theme_council.R @@ -81,7 +81,7 @@ #' use_manual_font_sizes = TRUE #' ) #' -#' fetch_ctu_geo() %>% +#' fetch_ctu_geo() %>% #' ggplot() + #' geom_sf() + #' theme_council_geo() From b15d0aeed1275813c245d0d7d3cfcf26d80f9dea Mon Sep 17 00:00:00 2001 From: ehesch Date: Thu, 20 Oct 2022 18:58:59 -0500 Subject: [PATCH 09/13] rebuild --- NAMESPACE | 15 +++++++++ man/blue_cascade.Rd | 4 ++- man/colors.Rd | 1 + man/council.pal.Rd | 1 + man/council_pal2.Rd | 1 + man/fetch_county_geo.Rd | 33 +++++++++++++++---- man/import_from_gis.Rd | 9 ++++-- man/map_council_continuous.Rd | 61 +++++++++++++++++++++++++++++++++++ man/scale_color_council.Rd | 1 + man/scale_fill_council.Rd | 1 + man/theme_council.Rd | 11 ++++++- 11 files changed, 127 insertions(+), 11 deletions(-) create mode 100644 man/map_council_continuous.Rd diff --git a/NAMESPACE b/NAMESPACE index e40d670..88d3899 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,19 +5,25 @@ export(council.pal) export(council_pal2) export(council_theme) export(fetch_county_geo) +export(fetch_ctu_geo) export(import_from_emissions) export(import_from_gis) export(import_from_gpkg) +export(map_council_continuous) export(scale_color_council) export(scale_fill_council) export(snippets_install) export(theme_council) +export(theme_council_geo) export(theme_council_open) importFrom(DBI,dbCanConnect) importFrom(DBI,dbConnect) importFrom(DBI,dbDisconnect) importFrom(DBI,dbGetQuery) importFrom(cli,cli_abort) +importFrom(dplyr,case_when) +importFrom(dplyr,mutate) +importFrom(dplyr,transmute) importFrom(fs,dir_create) importFrom(fs,dir_exists) importFrom(fs,dir_ls) @@ -27,15 +33,23 @@ importFrom(fs,path) importFrom(fs,path_file) importFrom(fs,path_home_r) importFrom(ggplot2,"%+replace%") +importFrom(ggplot2,aes) importFrom(ggplot2,discrete_scale) importFrom(ggplot2,element_blank) importFrom(ggplot2,element_line) importFrom(ggplot2,element_rect) importFrom(ggplot2,element_text) +importFrom(ggplot2,geom_sf) +importFrom(ggplot2,ggplot) importFrom(ggplot2,margin) importFrom(ggplot2,rel) +importFrom(ggplot2,scale_fill_gradient2) importFrom(ggplot2,theme) +importFrom(ggplot2,theme_void) importFrom(ggplot2,unit) +importFrom(ggspatial,annotation_north_arrow) +importFrom(ggspatial,annotation_scale) +importFrom(ggspatial,north_arrow_fancy_orienteering) importFrom(glue,glue) importFrom(magrittr,"%>%") importFrom(odbc,odbc) @@ -44,6 +58,7 @@ importFrom(purrr,map) importFrom(purrr,map_depth) importFrom(purrr,reduce) importFrom(rlang,abort) +importFrom(rlang,enquo) importFrom(sf,read_sf) importFrom(sf,st_as_sf) importFrom(sf,st_transform) diff --git a/man/blue_cascade.Rd b/man/blue_cascade.Rd index e2aa439..28b4ec7 100644 --- a/man/blue_cascade.Rd +++ b/man/blue_cascade.Rd @@ -5,7 +5,8 @@ \alias{blue_cascade} \title{Council blue menu background and text colors} \format{ -A named list of 8 lists. Each item contains a named list of two items: +A named list of 8 lists. Each item contains a named list +of two items: - "background" is the background or fill color - "color" is the text or contrast color \describe{ @@ -40,6 +41,7 @@ Other aesthetics: \code{\link{colors}}, \code{\link{council.pal}()}, \code{\link{council_pal2}()}, +\code{\link{map_council_continuous}()}, \code{\link{scale_color_council}()}, \code{\link{scale_fill_council}()}, \code{\link{theme_council}()} diff --git a/man/colors.Rd b/man/colors.Rd index 956cb93..a26005e 100644 --- a/man/colors.Rd +++ b/man/colors.Rd @@ -58,6 +58,7 @@ Other aesthetics: \code{\link{blue_cascade}}, \code{\link{council.pal}()}, \code{\link{council_pal2}()}, +\code{\link{map_council_continuous}()}, \code{\link{scale_color_council}()}, \code{\link{scale_fill_council}()}, \code{\link{theme_council}()} diff --git a/man/council.pal.Rd b/man/council.pal.Rd index 8c9c05e..9436956 100644 --- a/man/council.pal.Rd +++ b/man/council.pal.Rd @@ -31,6 +31,7 @@ Other aesthetics: \code{\link{blue_cascade}}, \code{\link{colors}}, \code{\link{council_pal2}()}, +\code{\link{map_council_continuous}()}, \code{\link{scale_color_council}()}, \code{\link{scale_fill_council}()}, \code{\link{theme_council}()} diff --git a/man/council_pal2.Rd b/man/council_pal2.Rd index 0767710..3ebd312 100644 --- a/man/council_pal2.Rd +++ b/man/council_pal2.Rd @@ -18,6 +18,7 @@ Other aesthetics: \code{\link{blue_cascade}}, \code{\link{colors}}, \code{\link{council.pal}()}, +\code{\link{map_council_continuous}()}, \code{\link{scale_color_council}()}, \code{\link{scale_fill_council}()}, \code{\link{theme_council}()} diff --git a/man/fetch_county_geo.Rd b/man/fetch_county_geo.Rd index bb7ba01..95f9012 100644 --- a/man/fetch_county_geo.Rd +++ b/man/fetch_county_geo.Rd @@ -2,27 +2,48 @@ % Please edit documentation in R/fetch_county_geo.R \name{fetch_county_geo} \alias{fetch_county_geo} -\title{Fetch standardized county geography} +\alias{fetch_ctu_geo} +\title{Fetch standardized geographies} \usage{ fetch_county_geo(core = TRUE, ...) + +fetch_ctu_geo(core = TRUE, ...) } \arguments{ -\item{core}{logical, whether to include all counties in the MPO. Default is \code{TRUE}.} +\item{core}{logical, whether to include all counties in the MPO. +Default is \code{TRUE}.} -\item{...}{Arguments passed to \verb{[tigris::counties]}} +\item{...}{Arguments passed to \verb{[tigris]} functions} } \value{ -An \code{\link{sf}} object containing county geographies. +An \code{\link{sf}} object containing specified geographies. } \description{ -Fetch standardized county geography +The default \code{fetch_county_geo()} to return county outlines, plus a suite of other functions to return more niche geographies. + +To get city, township, and unorganized territory (CTU) boundaries, use \code{fetch_ctu_geo()}. } \note{ This function relies on \verb{[\{rlang\}]} internal functions. } \examples{ \dontrun{ -fetch_county_geo() +library(ggplot2) + +fetch_county_geo() \%>\% + # ggplot() + + # geom_sf() + + # theme_void() + + fetch_ctu_geo() \%>\% + ggplot() + + geom_sf(fill = "grey90") + + theme_void() + + geom_sf_text(aes(label = CTU_NAME), + colour = "black", + check_overlap = F, + size = 2 + ) } } diff --git a/man/import_from_gis.Rd b/man/import_from_gis.Rd index 517b6c3..614b953 100644 --- a/man/import_from_gis.Rd +++ b/man/import_from_gis.Rd @@ -29,9 +29,12 @@ Import a dataset from ArcCatalog } \note{ See \code{vignette("Options")} to review package options. -You must be set up with the appropriate database drivers to use this function. -\strong{Windows} users need ODBC with Microsoft SQL. Contact IS support for ODBC installation. -\strong{Mac} users need \code{unixodbc} and \code{freetds}. See instructions in the \href{https://furry-adventure-596f3adb.pages.github.io/database-connections.html}{onboarding guide} +You must be set up with the appropriate database drivers +to use this function. +\strong{Windows} users need ODBC with Microsoft SQL. +Contact IS support for ODBC installation. +\strong{Mac} users need \code{unixodbc} and \code{freetds}. +See instructions in the \href{https://furry-adventure-596f3adb.pages.github.io/database-connections.html}{onboarding guide} \if{html}{\out{
}}\preformatted{ This function relies on `[\{rlang\}]` internal functions. }\if{html}{\out{
}} diff --git a/man/map_council_continuous.Rd b/man/map_council_continuous.Rd new file mode 100644 index 0000000..a8fa2c9 --- /dev/null +++ b/man/map_council_continuous.Rd @@ -0,0 +1,61 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/map_council.R +\name{map_council_continuous} +\alias{map_council_continuous} +\title{Council map starters} +\usage{ +map_council_continuous( + df, + .fill, + .lwd = 0.5, + .low = "#8c510a", + .mid = "white", + .high = "#01665e", + .midpoint = 0 +) +} +\arguments{ +\item{df}{The \code{sf} object to be mapped} + +\item{.fill}{For continuous data, the variable which should be used to fill polygons} + +\item{.lwd}{The line width of polygons, default setting is \code{0.5}.} + +\item{.low}{The color to fill the lowest number. Default is brown.} + +\item{.mid}{The color to fill the midpoint number. Default is white} + +\item{.high}{The color to fill the highest number. Default is teal} + +\item{.midpoint}{The midpoint of a diverging color scheme. Default is \code{0}.} +} +\value{ +a \link{ggplot2} plot +} +\description{ +Building on functionality for creating maps When mapping continuous data, \code{map_council_continuous()} could save some work. +} +\note{ +This function relies on \verb{[\{rlang\}]} internal functions. +} +\examples{ +\dontrun{ +library(ggplot2) +library(councilR) + +fetch_ctu_geo() \%>\% + map_council_continuous(.fill = ALAND, .midpoint = 5e7) +} + +} +\seealso{ +Other aesthetics: +\code{\link{blue_cascade}}, +\code{\link{colors}}, +\code{\link{council.pal}()}, +\code{\link{council_pal2}()}, +\code{\link{scale_color_council}()}, +\code{\link{scale_fill_council}()}, +\code{\link{theme_council}()} +} +\concept{aesthetics} diff --git a/man/scale_color_council.Rd b/man/scale_color_council.Rd index ccfd8ff..2fd3d23 100644 --- a/man/scale_color_council.Rd +++ b/man/scale_color_council.Rd @@ -35,6 +35,7 @@ Other aesthetics: \code{\link{colors}}, \code{\link{council.pal}()}, \code{\link{council_pal2}()}, +\code{\link{map_council_continuous}()}, \code{\link{scale_fill_council}()}, \code{\link{theme_council}()} } diff --git a/man/scale_fill_council.Rd b/man/scale_fill_council.Rd index 8dfff49..5524a76 100644 --- a/man/scale_fill_council.Rd +++ b/man/scale_fill_council.Rd @@ -31,6 +31,7 @@ Other aesthetics: \code{\link{colors}}, \code{\link{council.pal}()}, \code{\link{council_pal2}()}, +\code{\link{map_council_continuous}()}, \code{\link{scale_color_council}()}, \code{\link{theme_council}()} } diff --git a/man/theme_council.Rd b/man/theme_council.Rd index 45f874a..daddeee 100644 --- a/man/theme_council.Rd +++ b/man/theme_council.Rd @@ -3,6 +3,7 @@ \name{theme_council} \alias{theme_council} \alias{theme_council_open} +\alias{theme_council_geo} \title{Council ggplot2 theme} \usage{ theme_council( @@ -26,6 +27,8 @@ theme_council_open( font_sizes = list(title = 22, subtitle = 16, axis_title = 14, axis_text = 11, legend_title = 14, legend_text = 10, caption = 8, strip = 14) ) + +theme_council_geo() } \arguments{ \item{base_size}{numeric, base font size, given in pts. Default is \code{11}} @@ -46,7 +49,7 @@ theme_council_open( a \code{\link[ggplot2:theme]{ggplot2::theme()}} object } \description{ -The default \code{theme_council()} plus a more simple \code{theme_council_open()} for making MetCouncil figures. \code{theme_council()} will be appropriate in most cases while \code{theme_council_open()} is appropriate for single scatter plots or line graphs. +The default \code{theme_council()} plus a more simple \code{theme_council_open()} for making MetCouncil figures. \code{theme_council()} will be appropriate in most cases while \code{theme_council_open()} is appropriate for single scatter plots or line graphs. For geospatial plots, \code{theme_council_geo()} may be useful to set some initial parameters. Please note that the y-axis text is horizontal, and long axis names will need to be wrapped; \url{stringr::str_wrap()} is useful for managing length. For example, consider using this piece of code: \code{labs(y = stringr::str_wrap("Axis labels are now horizontal, but you still need to insert some code to wrap long labels", width = 15))} @@ -122,6 +125,11 @@ ggplot(datasets::iris) + use_showtext = TRUE, use_manual_font_sizes = TRUE ) + +fetch_ctu_geo() \%>\% + ggplot() + + geom_sf() + + theme_council_geo() } } @@ -131,6 +139,7 @@ Other aesthetics: \code{\link{colors}}, \code{\link{council.pal}()}, \code{\link{council_pal2}()}, +\code{\link{map_council_continuous}()}, \code{\link{scale_color_council}()}, \code{\link{scale_fill_council}()} } From 181ea5d42cd99b7fc94c82fdc78ec0e9d6e33d7e Mon Sep 17 00:00:00 2001 From: Liz Roten Date: Mon, 31 Oct 2022 14:23:55 -0500 Subject: [PATCH 10/13] specify ggplot2 package --- R/map_council.R | 15 ++++++++++----- R/theme_council.R | 10 +++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/R/map_council.R b/R/map_council.R index 18cbff7..90b4139 100644 --- a/R/map_council.R +++ b/R/map_council.R @@ -38,16 +38,21 @@ map_council_continuous <- function(df, .mid = "white", .high = "#01665e", .midpoint = 0) { + + rlang:::check_number(.lwd) + rlang:::check_number(.midpoint) + df %>% - ggplot() + - geom_sf(aes(fill = !!enquo(.fill)), lwd = .lwd) + + ggplot2::ggplot() + + ggplot2::geom_sf(aes(fill = !!enquo(.fill)), lwd = .lwd) + theme_council_geo() + - scale_fill_gradient2(low = .low, mid = .mid, high = .high, midpoint = .midpoint) + - annotation_scale( + ggplot2::scale_fill_gradient2(low = .low, mid = .mid, + high = .high, midpoint = .midpoint) + + ggplot2::annotation_scale( location = "bl", bar_cols = c("grey60", "white") ) + - annotation_north_arrow( + ggspatial::annotation_north_arrow( location = "tr", which_north = "true", # pad_x = unit(0.4, "in"), pad_y = unit(0.4, "in"), style = north_arrow_fancy_orienteering( diff --git a/R/theme_council.R b/R/theme_council.R index a028134..9593fdc 100644 --- a/R/theme_council.R +++ b/R/theme_council.R @@ -334,7 +334,7 @@ theme_council <- function(base_size = 11, panel.background = ggplot2::element_blank(), panel.border = ggplot2::element_blank(), panel.grid = ggplot2::element_line(colour = "grey92"), - panel.grid.minor = element_blank(), # ggplot2::element_line(size = ggplot2::rel(0.5)), + panel.grid.minor = ggplot2::element_blank(), # ggplot2::element_line(size = ggplot2::rel(0.5)), panel.grid.major = ggplot2::element_line(size = ggplot2::rel(1)), panel.spacing = ggplot2::unit(half_line, "pt"), panel.spacing.x = NULL, @@ -455,11 +455,11 @@ theme_council_geo <- function() { # Starts with theme_void and then modifies some parts ggplot2::`%+replace%`( - theme_void(), + ggplot2::theme_void(), ggplot2::theme( - legend.title = element_text(size = 6), - legend.text = element_text(size = 6), - legend.key.size = unit(.75, "lines") + legend.title = ggplot2::element_text(size = 6), + legend.text = ggplot2::element_text(size = 6), + legend.key.size = ggplot2::unit(.75, "lines") ) ) } From 8d27aff01c16c9372e6961832bd93d989d1d391a Mon Sep 17 00:00:00 2001 From: Liz Roten Date: Mon, 31 Oct 2022 14:26:44 -0500 Subject: [PATCH 11/13] specify ggspatial --- R/map_council.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/map_council.R b/R/map_council.R index 90b4139..1b4d3d9 100644 --- a/R/map_council.R +++ b/R/map_council.R @@ -48,7 +48,7 @@ map_council_continuous <- function(df, theme_council_geo() + ggplot2::scale_fill_gradient2(low = .low, mid = .mid, high = .high, midpoint = .midpoint) + - ggplot2::annotation_scale( + ggspatial::annotation_scale( location = "bl", bar_cols = c("grey60", "white") ) + From ced130dcd39c59303caf54040998b69a39c8a2c0 Mon Sep 17 00:00:00 2001 From: Liz Roten Date: Mon, 31 Oct 2022 14:26:58 -0500 Subject: [PATCH 12/13] update documentation --- R/fetch_county_geo.R | 6 +++--- R/map_council.R | 19 ++++++++++++------- man/fetch_county_geo.Rd | 6 +++--- man/map_council_continuous.Rd | 19 ++++++++++++------- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/R/fetch_county_geo.R b/R/fetch_county_geo.R index 55b3b20..7944bdb 100644 --- a/R/fetch_county_geo.R +++ b/R/fetch_county_geo.R @@ -16,9 +16,9 @@ #' library(ggplot2) #' #' fetch_county_geo() %>% -#' # ggplot() + -#' # geom_sf() + -#' # theme_void() +#' ggplot() + +#' geom_sf() + +#' theme_void() #' #' fetch_ctu_geo() %>% #' ggplot() + diff --git a/R/map_council.R b/R/map_council.R index 1b4d3d9..1f7f2e1 100644 --- a/R/map_council.R +++ b/R/map_council.R @@ -1,14 +1,19 @@ #' @title Council map starters #' -#' @description Building on functionality for creating maps When mapping continuous data, `map_council_continuous()` could save some work. +#' @description Building on functionality for creating maps when mapping continuous data, `map_council_continuous()` could save some work. #' #' @param df The `sf` object to be mapped -#' @param .fill For continuous data, the variable which should be used to fill polygons -#' @param .lwd The line width of polygons, default setting is `0.5`. -#' @param .low The color to fill the lowest number. Default is brown. -#' @param .mid The color to fill the midpoint number. Default is white -#' @param .high The color to fill the highest number. Default is teal -#' @param .midpoint The midpoint of a diverging color scheme. Default is `0`. +#' @param .fill For continuous data, the variable (column name) which +#' should be used to fill polygons +#' @param .lwd numeric, line width of polygons, default setting is `0.5`. +#' @param .low character, color name or hex code to fill the lowest number. +#' Default is `"#8c510a"` (brown) +#' @param .mid character, color name or hex code to fill the midpoint number. +#' Default is `"white"` +#' @param .high character, color name or hex code to fill the highest number. +#' Default is `"#01665e"` (teal) +#' @param .midpoint numeric, midpoint of a diverging color scheme. +#' Default is `0`. #' #' @return a [ggplot2] plot #' @export diff --git a/man/fetch_county_geo.Rd b/man/fetch_county_geo.Rd index 95f9012..b3f087a 100644 --- a/man/fetch_county_geo.Rd +++ b/man/fetch_county_geo.Rd @@ -31,9 +31,9 @@ This function relies on \verb{[\{rlang\}]} internal functions. library(ggplot2) fetch_county_geo() \%>\% - # ggplot() + - # geom_sf() + - # theme_void() + ggplot() + + geom_sf() + + theme_void() fetch_ctu_geo() \%>\% ggplot() + diff --git a/man/map_council_continuous.Rd b/man/map_council_continuous.Rd index a8fa2c9..9e0b454 100644 --- a/man/map_council_continuous.Rd +++ b/man/map_council_continuous.Rd @@ -17,23 +17,28 @@ map_council_continuous( \arguments{ \item{df}{The \code{sf} object to be mapped} -\item{.fill}{For continuous data, the variable which should be used to fill polygons} +\item{.fill}{For continuous data, the variable (column name) which +should be used to fill polygons} -\item{.lwd}{The line width of polygons, default setting is \code{0.5}.} +\item{.lwd}{numeric, line width of polygons, default setting is \code{0.5}.} -\item{.low}{The color to fill the lowest number. Default is brown.} +\item{.low}{character, color name or hex code to fill the lowest number. +Default is \code{"#8c510a"} (brown)} -\item{.mid}{The color to fill the midpoint number. Default is white} +\item{.mid}{character, color name or hex code to fill the midpoint number. +Default is \code{"white"}} -\item{.high}{The color to fill the highest number. Default is teal} +\item{.high}{character, color name or hex code to fill the highest number. +Default is \code{"#01665e"} (teal)} -\item{.midpoint}{The midpoint of a diverging color scheme. Default is \code{0}.} +\item{.midpoint}{numeric, midpoint of a diverging color scheme. +Default is \code{0}.} } \value{ a \link{ggplot2} plot } \description{ -Building on functionality for creating maps When mapping continuous data, \code{map_council_continuous()} could save some work. +Building on functionality for creating maps when mapping continuous data, \code{map_council_continuous()} could save some work. } \note{ This function relies on \verb{[\{rlang\}]} internal functions. From d8a8ec6851d63afed56d736ab615eb458d484719 Mon Sep 17 00:00:00 2001 From: Liz Roten Date: Mon, 31 Oct 2022 14:28:48 -0500 Subject: [PATCH 13/13] increment date, version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 47379e6..2ac0820 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: councilR Title: Functions and Templates for the Metropolitan Council -Version: 0.1.4 -Date: 2022-10-20 +Version: 0.1.5 +Date: 2022-10-31 Authors@R: c( person("Metropolitan Council", role = "cph"), person("Liz", "Roten", , "liz.roten@metc.state.mn.us", role = c("cre", "aut"),