diff --git a/DESCRIPTION b/DESCRIPTION index 2ac0820..df5558f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,16 +2,16 @@ Type: Package Package: councilR Title: Functions and Templates for the Metropolitan Council Version: 0.1.5 -Date: 2022-10-31 +Date: 2022-11-04 Authors@R: c( person("Metropolitan Council", role = "cph"), person("Liz", "Roten", , "liz.roten@metc.state.mn.us", role = c("cre", "aut"), comment = c(ORCID = "0000-0002-5346-3549")), - person("Garrick", "Aden-Buie", , "garrick@adenbuie.com", role = "ctb", - comment = c(ORCID = "0000-0002-7111-0077")), person("Ellen", "Esch", , "ellen.esch@metc.state.mn.us", role = "ctb", comment = c(ORCID = "0000-0002-4253-0910")), - person("Mauricio", "León", , "mauricio.leon@metc.state.mn.us", role = "ctb") + person("Mauricio", "León", , "mauricio.leon@metc.state.mn.us", role = "ctb"), + person("Garrick", "Aden-Buie", , "garrick@adenbuie.com", role = "ctb", + comment = c(ORCID = "0000-0002-7111-0077")) ) Description: A collection of commonly used templates, color palettes, and functions for R users at the Metropolitan Council. @@ -22,8 +22,10 @@ Depends: Imports: cli (>= 3.3.0), DBI (>= 1.1.0), + dplyr (>= 1.0.10), fs (>= 1.4), ggplot2 (>= 3.3.0), + ggspatial (>= 1.1.6), glue (>= 1.4.0), magrittr (>= 1.5), odbc (>= 1.2.2), @@ -33,9 +35,7 @@ Imports: sf (>= 0.9.5), tictoc (>= 1.0), tigris (>= 1.6.1), - utils, - ggspatial (>= 1.1.6), - dplyr (>= 1.0.10) + utils Suggests: citr (>= 0.3.2), cowplot (>= 1.1.1), diff --git a/NEWS.md b/NEWS.md index 13f19ed..cc89476 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,14 @@ +# v.0.1.5 (2022-11-04) + +Geography and plotting function expansion + +- `fetch_ctu_geo()` fetches CTU geographies +- `theme_council_geo()` provides a ggplot2 theme for maps +- `map_council_continuous()` allows you to map a given geography using a specific variable/column. + +Significant improvements in testing. + + # v.0.1.4 (2022-10-14) ## `theme_council()` font patch diff --git a/R/fetch_county_geo.R b/R/fetch_county_geo.R index 7944bdb..2e46b3b 100644 --- a/R/fetch_county_geo.R +++ b/R/fetch_county_geo.R @@ -16,11 +16,11 @@ #' library(ggplot2) #' #' fetch_county_geo() %>% -#' ggplot() + -#' geom_sf() + -#' theme_void() +#' ggplot() + +#' geom_sf() + +#' theme_void() #' -#' fetch_ctu_geo() %>% +#' fetch_ctu_geo() %>% #' ggplot() + #' geom_sf(fill = "grey90") + #' theme_void() + @@ -45,32 +45,32 @@ fetch_county_geo <- function(core = TRUE, ...) { county_list <- if (core == TRUE) { c( - "Anoka", - "Carver", - "Dakota", - "Hennepin", - "Ramsey", - "Scott", - "Washington" + "003", # "Anoka", + "019", # "Carver", + "037", # "Dakota", + "053", # "Hennepin", + "123", # "Ramsey", + "139", # "Scott", + "163" # "Washington" ) } else if (core == FALSE) { c( - "Anoka", - "Carver", - "Dakota", - "Hennepin", - "Ramsey", - "Scott", - "Sherburne", - "Washington", - "Wright" + "003", # "Anoka", + "019", # "Carver", + "037", # "Dakota", + "053", # "Hennepin", + "123", # "Ramsey", + "139", # "Scott", + "163", # "Washington" + "141", # "Sherburne", + "171" # "Wright" ) } # fetch county geograp - mn_counties <- tigris::counties(state = "MN", ...) + mn_counties <- tigris::counties(state = 27, ...) - county_sf <- mn_counties[mn_counties$NAME %in% county_list, ] + county_sf <- mn_counties[mn_counties$COUNTYFP %in% county_list, ] return(county_sf) @@ -86,66 +86,72 @@ fetch_ctu_geo <- function(core = TRUE, ...) { county_list <- if (core == TRUE) { c( - "Anoka", - "Carver", - "Dakota", - "Hennepin", - "Ramsey", - "Scott", - "Washington" + "003", # "Anoka", + "019", # "Carver", + "037", # "Dakota", + "053", # "Hennepin", + "123", # "Ramsey", + "139", # "Scott", + "163" # "Washington" ) } else if (core == FALSE) { c( - "Anoka", - "Carver", - "Dakota", - "Hennepin", - "Ramsey", - "Scott", - "Sherburne", - "Washington", - "Wright" + "003", # "Anoka", + "019", # "Carver", + "037", # "Dakota", + "053", # "Hennepin", + "123", # "Ramsey", + "139", # "Scott", + "163", # "Washington" + "141", # "Sherburne", + "171" # "Wright" ) } - cities <- tigris::county_subdivisions( - state = "MN", + cities_geo <- tigris::county_subdivisions( + state = 27, county = county_list, - class = "sf" + class = "sf", + ... ) %>% - mutate(NAME = 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) - transmute( - CTU_NAME = NAME, - ALAND = ALAND, - AWATER = AWATER + dplyr::mutate( + NAME = dplyr::case_when( + LSAD == 44 ~ paste(NAME, "Twp."), + LSAD == 46 ~ paste(NAME, "(unorg.)"), + TRUE ~ NAME + ) ) + cities <- if (core == TRUE) { + cities_geo %>% + dplyr::transmute( + CTU_NAME = NAME, + ALAND = ALAND, + AWATER = AWATER + ) + } else if (core == FALSE) { + cities_geo %>% + dplyr::group_by(NAME) %>% + dplyr::mutate(n = dplyr::n()) %>% + dplyr::left_join(sf::st_drop_geometry(cities_geo) %>% + dplyr::transmute( + COUNTYFP = COUNTYFP, + CONAME = NAME + )) %>% + dplyr::mutate(CTU_NAME = dplyr::if_else( + n > 1 & LSAD != 25, + paste0(NAME, " - ", CONAME, " Co."), # cities dont get merged + NAME + )) %>% + dplyr::group_by(CTU_NAME) %>% + dplyr::summarise( + geometry = sf::st_union(geometry), + ALAND = sum(ALAND, na.rm = T), + AWATER = sum(AWATER, na.rm = T) + ) %>% + dplyr::arrange(CTU_NAME) + } + return(cities) } - - -#' @rdname fetch_ctu_geo -#' @export -#' diff --git a/R/import_from_emissions.R b/R/import_from_emissions.R index 42dd1c1..c3ef6a2 100644 --- a/R/import_from_emissions.R +++ b/R/import_from_emissions.R @@ -50,7 +50,6 @@ import_from_emissions <- function(table_name, local = TRUE, serv = "dbsqlcl11t.test.local,65414", db = "CD_Emissions") { - # check input types purrr::map( c(table_name, serv, uid, pwd, db), diff --git a/R/import_from_gis.R b/R/import_from_gis.R index d628cb7..6ab499f 100644 --- a/R/import_from_gis.R +++ b/R/import_from_gis.R @@ -5,6 +5,7 @@ #' Must match the database name in `query`. #' @param uid character, user ID. Default is `getOption("councilR.uid")` #' @param pwd character, user password. Default is `getOption("councilR.pwd")`. +#' @param .quiet logical, whether to print time elapsed message. #' #' @note See `vignette("Options")` to review package options. #' You must be set up with the appropriate database drivers @@ -35,13 +36,16 @@ import_from_gis <- function(query, dbname = "GISLibrary", uid = getOption("councilR.uid"), - pwd = getOption("councilR.pwd")) { + pwd = getOption("councilR.pwd"), + .quiet = FALSE) { purrr::map( c(query, dbname, uid, pwd), rlang:::check_string ) - tictoc::tic() + if (.quiet == FALSE) { + tictoc::tic() + } if (DBI::dbCanConnect(odbc::odbc(), # driver = "FreeTDS", dbname, diff --git a/R/import_from_gpkg.R b/R/import_from_gpkg.R index 302d75d..a6f6edb 100644 --- a/R/import_from_gpkg.R +++ b/R/import_from_gpkg.R @@ -36,7 +36,6 @@ import_from_gpkg <- function(link, .crs = 4326, keep_temp = FALSE, .quiet = TRUE) { - # check input types purrr::map( c(link), diff --git a/R/map_council.R b/R/map_council.R index 1f7f2e1..e584970 100644 --- a/R/map_council.R +++ b/R/map_council.R @@ -20,7 +20,6 @@ #' #' @family aesthetics #' -#' @note This function relies on `[{rlang}]` internal functions. #' #' @examples #' \dontrun{ @@ -43,16 +42,14 @@ map_council_continuous <- function(df, .mid = "white", .high = "#01665e", .midpoint = 0) { - - rlang:::check_number(.lwd) - rlang:::check_number(.midpoint) - df %>% ggplot2::ggplot() + ggplot2::geom_sf(aes(fill = !!enquo(.fill)), lwd = .lwd) + theme_council_geo() + - ggplot2::scale_fill_gradient2(low = .low, mid = .mid, - high = .high, midpoint = .midpoint) + + ggplot2::scale_fill_gradient2( + low = .low, mid = .mid, + high = .high, midpoint = .midpoint + ) + ggspatial::annotation_scale( location = "bl", bar_cols = c("grey60", "white") diff --git a/R/theme_council.R b/R/theme_council.R index 9593fdc..9c971a8 100644 --- a/R/theme_council.R +++ b/R/theme_council.R @@ -185,7 +185,7 @@ theme_council <- function(base_size = 11, half_line <- base_size / 2 - t <- theme( + t <- ggplot2::theme( # SETUP ----- line = ggplot2::element_line( @@ -249,7 +249,7 @@ theme_council <- function(base_size = 11, ), ## ticks ---- - axis.ticks = element_line(color = "grey92"), + axis.ticks = ggplot2::element_line(color = "grey92"), axis.ticks.length = ggplot2::unit(half_line / 2, "pt"), axis.ticks.length.x = NULL, axis.ticks.length.x.top = NULL, @@ -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 = ggplot2::element_blank(), # ggplot2::element_line(size = ggplot2::rel(0.5)), + panel.grid.minor = ggplot2::element_blank(), panel.grid.major = ggplot2::element_line(size = ggplot2::rel(1)), panel.spacing = ggplot2::unit(half_line, "pt"), panel.spacing.x = NULL, @@ -415,27 +415,11 @@ theme_council <- function(base_size = 11, #' @rdname theme_council #' @export -#' -theme_council_open <- function(base_size = 11, - base_family = "", - base_line_size = base_size / 22, - base_rect_size = base_size / 22, - use_showtext = FALSE, - use_manual_font_sizes = FALSE, - font_sizes = list( - "title" = 22, - "subtitle" = 16, - "axis_title" = 14, - "axis_text" = 11, - "legend_title" = 14, - "legend_text" = 10, - "caption" = 8, - "strip" = 14 - )) { - +#' @param ... arguments passed to `theme_council()` +theme_council_open <- function(...) { # Starts with theme_council and then modifies some parts ggplot2::`%+replace%`( - theme_council(), + theme_council(...), ggplot2::theme( # remove grid lines panel.grid.minor = ggplot2::element_blank(), @@ -451,19 +435,38 @@ theme_council_open <- function(base_size = 11, #' @rdname theme_council #' @export #' -theme_council_geo <- function() { - # Starts with theme_void and then modifies some parts +theme_council_geo <- function(...) { + # Starts with theme_council() then modifies + # to match theme_void() ggplot2::`%+replace%`( - ggplot2::theme_void(), + theme_council(...), ggplot2::theme( - legend.title = ggplot2::element_text(size = 6), - legend.text = ggplot2::element_text(size = 6), - legend.key.size = ggplot2::unit(.75, "lines") + line = ggplot2::element_blank(), + rect = ggplot2::element_blank(), + axis.title = ggplot2::element_blank(), + axis.ticks.length = unit(0, "pt"), + axis.ticks.length.x = NULL, + axis.ticks.length.x.top = NULL, + axis.ticks.length.x.bottom = NULL, + axis.ticks.length.y = NULL, + axis.ticks.length.y.left = NULL, + axis.ticks.length.y.right = NULL, + axis.text = ggplot2::element_blank(), + axis.text.x = ggplot2::element_blank(), + axis.text.x.bottom = ggplot2::element_blank(), + axis.text.x.top = ggplot2::element_blank(), + axis.text.y = ggplot2::element_blank(), + axis.text.y.left = ggplot2::element_blank(), + axis.text.y.right = ggplot2::element_blank(), + panel.grid = ggplot2::element_blank(), + panel.grid.major = ggplot2::element_blank(), + panel.grid.minor = ggplot2::element_blank(), + + # legend.title = ggplot2::element_text(size = 6), + # legend.text = ggplot2::element_text(size = 6), + legend.key.size = ggplot2::unit(.75, "lines"), + complete = TRUE ) ) } - -#' @rdname theme_council -#' @export -#' diff --git a/man/fetch_county_geo.Rd b/man/fetch_county_geo.Rd index b3f087a..2e863e2 100644 --- a/man/fetch_county_geo.Rd +++ b/man/fetch_county_geo.Rd @@ -31,11 +31,11 @@ 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() \%>\% +fetch_ctu_geo() \%>\% ggplot() + geom_sf(fill = "grey90") + theme_void() + diff --git a/man/import_from_gis.Rd b/man/import_from_gis.Rd index 614b953..e4d79de 100644 --- a/man/import_from_gis.Rd +++ b/man/import_from_gis.Rd @@ -8,7 +8,8 @@ import_from_gis( query, dbname = "GISLibrary", uid = getOption("councilR.uid"), - pwd = getOption("councilR.pwd") + pwd = getOption("councilR.pwd"), + .quiet = FALSE ) } \arguments{ @@ -20,6 +21,8 @@ Must match the database name in \code{query}.} \item{uid}{character, user ID. Default is \code{getOption("councilR.uid")}} \item{pwd}{character, user password. Default is \code{getOption("councilR.pwd")}.} + +\item{.quiet}{logical, whether to print time elapsed message.} } \value{ an \code{\link{sf}} object diff --git a/man/map_council_continuous.Rd b/man/map_council_continuous.Rd index 9e0b454..157134a 100644 --- a/man/map_council_continuous.Rd +++ b/man/map_council_continuous.Rd @@ -40,9 +40,6 @@ 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) diff --git a/man/theme_council.Rd b/man/theme_council.Rd index a981bb9..72ee8d2 100644 --- a/man/theme_council.Rd +++ b/man/theme_council.Rd @@ -17,18 +17,9 @@ theme_council( legend_title = 14, legend_text = 10, caption = 8, strip = 14) ) -theme_council_open( - base_size = 11, - base_family = "", - base_line_size = base_size/22, - base_rect_size = base_size/22, - use_showtext = FALSE, - use_manual_font_sizes = FALSE, - 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_open(...) -theme_council_geo() +theme_council_geo(...) } \arguments{ \item{base_size}{numeric, base font size, given in pts. Default is \code{11}} @@ -44,6 +35,8 @@ theme_council_geo() \item{use_manual_font_sizes}{logical, use supplied font sizes.} \item{font_sizes}{named list, font sizes. Only used if \code{use_manual_font_sizes} is \code{TRUE}} + +\item{...}{arguments passed to \code{theme_council()}} } \value{ a \code{\link[ggplot2:theme]{ggplot2::theme()}} object diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R new file mode 100644 index 0000000..5ad7f3c --- /dev/null +++ b/tests/testthat/setup.R @@ -0,0 +1,5 @@ +options( + tigris_use_cache = TRUE, + progress_bar = FALSE, + tigris_refresh = FALSE +) diff --git a/tests/testthat/test-blue_cascade.R b/tests/testthat/test-blue_cascade.R new file mode 100644 index 0000000..66dce7a --- /dev/null +++ b/tests/testthat/test-blue_cascade.R @@ -0,0 +1,8 @@ +test_that("correct length", { + length(blue_cascade) %>% + testthat::expect_equal(8) +}) + +test_that("correct type", { + testthat::expect_type(blue_cascade, "list") +}) diff --git a/tests/testthat/test-fetch_county_geo.R b/tests/testthat/test-fetch_county_geo.R index 33537f9..0b601af 100644 --- a/tests/testthat/test-fetch_county_geo.R +++ b/tests/testthat/test-fetch_county_geo.R @@ -1,3 +1,15 @@ test_that("input check works", { testthat::expect_error(fetch_county_geo(core = "foo")) }) + +test_that("nrows correct", { + fetch_county_geo(year = "2020") %>% + nrow() %>% + testthat::expect_equal(7) +}) + +test_that("nrows correct", { + fetch_county_geo(core = FALSE, year = "2020") %>% + nrow() %>% + testthat::expect_equal(9) +}) diff --git a/tests/testthat/test-fetch_ctu_geo.R b/tests/testthat/test-fetch_ctu_geo.R new file mode 100644 index 0000000..41d7912 --- /dev/null +++ b/tests/testthat/test-fetch_ctu_geo.R @@ -0,0 +1,15 @@ +test_that("non T/F core fails", { + testthat::expect_error(fetch_ctu_geo(core = "foo")) +}) + +test_that("nrows correct", { + fetch_ctu_geo(year = "2020") %>% + nrow() %>% + testthat::expect_equal(193) +}) + +test_that("nrows correct", { + fetch_ctu_geo(core = FALSE, year = "2020") %>% + nrow() %>% + testthat::expect_equal(235) +}) diff --git a/tests/testthat/test-import_from_gis.R b/tests/testthat/test-import_from_gis.R index a250c0c..5bc9aaf 100644 --- a/tests/testthat/test-import_from_gis.R +++ b/tests/testthat/test-import_from_gis.R @@ -1,8 +1,7 @@ # Can import_from_gis() actually import from the GISLibrary database? -# skip on GH Actions, CRAN +# skip on GH Actions testthat::skip_on_ci() -testthat::skip_on_cran() # skip if not connected to VPN testthat::skip_if( @@ -18,7 +17,8 @@ testthat::test_that("airports spatial dataset", { uid = httr2::secret_decrypt("QUHBRb_yoy2RRj59qno8NVXA7mW402xkins", "COUNCILR_KEY"), pwd = httr2::secret_decrypt("IMcfHFuibrH6IsuwIE_vd9oJmNTlOkpt", "COUNCILR_KEY"), query = "GISLibrary.dbo.AIRPORTS", - dbname = "GISLibrary" + dbname = "GISLibrary", + .quiet = TRUE ) # test that all airports are included diff --git a/tests/testthat/test-map_council.R b/tests/testthat/test-map_council.R new file mode 100644 index 0000000..664b951 --- /dev/null +++ b/tests/testthat/test-map_council.R @@ -0,0 +1,23 @@ +test_that("correct class returned", { + fetch_ctu_geo(year = "2020") %>% + map_council_continuous( + .fill = ALAND, + .midpoint = 5e7, + .lwd = 0.5 + ) %>% + testthat::expect_s3_class("ggplot") +}) + +test_that("ggplot data same as input data ", { + mp <- fetch_ctu_geo(year = "2020") %>% + map_council_continuous( + .fill = ALAND, + .midpoint = 5e7, + .lwd = 0.5 + ) + + testthat::expect_equal( + fetch_ctu_geo(year = "2020")$ALAND, + mp$data$ALAND + ) +}) diff --git a/tests/testthat/test-scale_fill_council.R b/tests/testthat/test-scale_fill_council.R new file mode 100644 index 0000000..c380407 --- /dev/null +++ b/tests/testthat/test-scale_fill_council.R @@ -0,0 +1,9 @@ +test_that("correct color class", { + scale_color_council() %>% + testthat::expect_s3_class("ScaleDiscrete") +}) + +test_that("correct fill class", { + scale_fill_council() %>% + testthat::expect_s3_class("ScaleDiscrete") +}) diff --git a/tests/testthat/test-theme_council.R b/tests/testthat/test-theme_council.R new file mode 100644 index 0000000..6c03f44 --- /dev/null +++ b/tests/testthat/test-theme_council.R @@ -0,0 +1,82 @@ +test_that("correct class returned", { + theme_council() %>% + testthat::expect_s3_class("theme") +}) + +test_that("error on old theme", { + council_theme() %>% + testthat::expect_error() +}) + +test_that("individual color elements correct", { + th <- theme_council() + + testthat::expect_equal(th$panel.grid$colour, "grey92") + testthat::expect_equal(th$axis.text$colour, "gray30") + testthat::expect_equal(th$axis.line, ggplot2::element_blank()) + testthat::expect_equal(th$plot.background$colour, "#FFFFFF") + testthat::expect_equal(th$text$colour, "#000000") +}) + +test_that("individual font size elements correct", { + th <- theme_council( + use_manual_font_sizes = TRUE, + font_sizes = list( + "title" = 24, + "subtitle" = 17, + "axis_title" = 15, + "axis_text" = 12, + "legend_title" = 16, + "legend_text" = 11, + "caption" = 40, + "strip" = 10 + ) + ) + + testthat::expect_equal(th$plot.title$size, 24) + testthat::expect_equal(th$plot.subtitle$size, 17) + testthat::expect_equal(th$axis.title.x$size, 15) + testthat::expect_equal(th$axis.title.y$size, 15) + testthat::expect_equal(th$axis.text$size, 12) + + testthat::expect_equal(th$legend.title$size, 16) + testthat::expect_equal(th$legend.text$size, 11) + testthat::expect_equal(th$plot.caption$size, 40) + testthat::expect_equal(th$strip.text$size, 10) +}) + +test_that("open theme is correct", { + th <- theme_council_open( + use_manual_font_sizes = TRUE, + font_sizes = list( + "title" = 24, + "subtitle" = 17, + "axis_title" = 15, + "axis_text" = 12, + "legend_title" = 16, + "legend_text" = 11, + "caption" = 40, + "strip" = 10 + ) + ) + + + testthat::expect_equal(th$panel.grid$colour, "grey92") + testthat::expect_equal(th$axis.text$colour, "gray30") + testthat::expect_equal(th$plot.background$colour, "#FFFFFF") + testthat::expect_equal(th$text$colour, "#000000") + testthat::expect_equal(th$panel.grid.minor, ggplot2::element_blank()) + testthat::expect_equal(th$panel.grid.major, ggplot2::element_blank()) + testthat::expect_equal(th$axis.line$colour, "grey92") +}) + + + +test_that("geo theme is mostly blank", { + th <- theme_council_geo() + + testthat::expect_equal(th$line, ggplot2::element_blank()) + testthat::expect_equal(th$rect, ggplot2::element_blank()) + testthat::expect_equal(th$panel.grid, ggplot2::element_blank()) + testthat::expect_equal(th$axis.text, ggplot2::element_blank()) +}) diff --git a/vignettes/Color.Rmd b/vignettes/Color.Rmd index 6f4e3de..ee9ce78 100644 --- a/vignettes/Color.Rmd +++ b/vignettes/Color.Rmd @@ -27,23 +27,30 @@ requireNamespace("stringr", quietly = TRUE) requireNamespace("cowplot", quietly = TRUE) requireNamespace("tibble", quietly = TRUE) requireNamespace("showtext", quietly = TRUE) - ``` This package contains a set of Council brand colors. These are values pulled directly from the Council Brand Standards [document](https://www.metrotransit.org/Data/Sites/1/media/logos/brand_standards.pdf) ```{r, plot-color-preview} -color_table <- tibble::tibble(name = names(colors), - value = colors) +color_table <- tibble::tibble( + name = names(colors), + value = colors +) -plots <- purrr::map(seq(1:length(colors)), function(x){ - ggplot(mapping = aes(xmin = 0, xmax = 1, - ymin = 0, ymax = 1 )) + +plots <- purrr::map(seq(1:length(colors)), function(x) { + ggplot(mapping = aes( + xmin = 0, xmax = 1, + ymin = 0, ymax = 1 + )) + geom_rect(fill = colors[x][[1]]) + - geom_label(aes(x = 0.5, - y = 0.5), - label = color_table[1][x,], - size = 3) + + geom_label( + aes( + x = 0.5, + y = 0.5 + ), + label = color_table[1][x, ], + size = 3 + ) + theme_void() }) cowplot::plot_grid(plotlist = plots) @@ -55,8 +62,9 @@ cowplot::plot_grid(plotlist = plots) First, lets create an example plot. ```{r, plot-example} -plot_example <- ggplot(datasets::airquality) + - aes(Solar.R, Wind, color = as.factor(Month)) + geom_point() +plot_example <- ggplot(datasets::airquality) + + aes(Solar.R, Wind, color = as.factor(Month)) + + geom_point() ``` @@ -66,7 +74,6 @@ color_range_blue <- colorRampPalette(c("#e0e3e8", colors$playDaBlue)) plot_example + scale_color_manual(values = color_range_blue(5)) + theme_council(use_showtext = F) - ``` ```{r, color-range-green} color_range_green <- colorRampPalette(c("#EEF3E5", colors$cdGreen)) @@ -74,8 +81,10 @@ color_range_green <- colorRampPalette(c("#EEF3E5", colors$cdGreen)) plot_example + scale_color_manual(values = color_range_green(5)) + theme_council(use_showtext = F) + - labs(y = stringr::str_wrap("Axis labels are now horizontal, but you still need to insert some code to wrap long labels", width = 15)) - + labs(y = stringr::str_wrap( + "Axis labels are now horizontal, but you still need to insert some code to wrap long labels", + width = 15 + )) ``` ## Blue cascade @@ -85,15 +94,21 @@ plot_example + ![Cascading menu on metrocouncil.org](blue_cascade_menu.png) ```{r, blue-plots} -blue_plots <- map(seq(1:length(blue_cascade)), function(x){ - ggplot(mapping = aes(xmin = 0, xmax = 1, - ymin = 0, ymax = 1)) + +blue_plots <- map(seq(1:length(blue_cascade)), function(x) { + ggplot(mapping = aes( + xmin = 0, xmax = 1, + ymin = 0, ymax = 1 + )) + geom_rect(fill = blue_cascade[x][[1]][1]) + - geom_text(aes(x = 0.5, - y = 0.5), - label = names(blue_cascade)[x], - color = blue_cascade[x][[1]][2], - size = 4) + + geom_text( + aes( + x = 0.5, + y = 0.5 + ), + label = names(blue_cascade)[x], + color = blue_cascade[x][[1]][2], + size = 4 + ) + theme_void() }) @@ -110,8 +125,7 @@ cowplot::plot_grid(plotlist = blue_plots) plot_example + councilR:::scale_color_council() + theme_council(use_showtext = F) + - labs(y = stringr::str_wrap("Axis labels are now horizontal, but you still need to insert some code to wrap long labels", width = 15)) - + labs(y = stringr::str_wrap("Axis labels are now horizontal, but you still need to insert some code to wrap long labels", width = 15)) ``` ## Update to `theme_council()` @@ -122,5 +136,16 @@ There is the traditional `theme_council()` but now also `theme_council_open()` w plot_example + councilR:::scale_color_council() + theme_council_open(use_showtext = F) + - labs(title = "This is theme_council_open()") + labs(title = "This is theme_council_open()") +``` + +`theme_council_geo()` is best for maps. + +```{r plot-county, eval = TRUE} +fetch_county_geo() %>% + ggplot() + + aes(fill = ALAND) + + geom_sf() + + theme_council_geo() + + labs(title = "Counties") ``` diff --git a/vignettes/Options.Rmd b/vignettes/Options.Rmd index 7b5a243..aebc75f 100644 --- a/vignettes/Options.Rmd +++ b/vignettes/Options.Rmd @@ -22,8 +22,9 @@ library(councilR) `{councilR}` has a few `options()` that can help the package run more smoothly. ```{r} -options(councilR.uid = "mc\\myuuid", # your user id - councilR.pwd = keyring::key_get("MetC") # your password +options( + councilR.uid = "mc\\myuuid", # your user id + councilR.pwd = keyring::key_get("MetC") # your password ) ``` diff --git a/vignettes/Spatial_helpers.Rmd b/vignettes/Spatial_helpers.Rmd index 5e6a6fa..6c04af6 100644 --- a/vignettes/Spatial_helpers.Rmd +++ b/vignettes/Spatial_helpers.Rmd @@ -45,7 +45,7 @@ Some datasets are maintained on [Minnesota Geospatial Commons](https://gisdata.m Pass this link to `import_from_gpkg()` to get the [sf]() object! -```{r} +```{r gpkg-query} regional_parks_commons <- import_from_gpkg("https://resources.gisdata.mn.gov/pub/gdrs/data/pub/us_mn_state_metc/plan_parks_regional/gpkg_plan_parks_regional.zip") head(regional_parks_commons) @@ -53,14 +53,28 @@ head(regional_parks_commons) If you can access internal databases, use your Council login user ID and password to access data from the GIS Library. For seamless access, see `vignette("Options")` to review package options. -```{r, eval = FALSE} +```{r gis-query, eval = FALSE} regional_parks_db <- import_from_gis(query = "PARKSREGIONAL") head(regional_parks_db) ``` A commonly fetched spatial dataset is the 7-county geography. `fetch_county_geo()` does just that. +You can also make a map quickly by using `map_council_continuous()`. This also adds a scale bar and cardinal indicator. -```{r, eval = FALSE} -fetch_county_geo() + +```{r plot-county, eval = TRUE} +fetch_county_geo() %>% + map_council_continuous(.fill = ALAND) + + labs(title = "Counties") +``` + + +You can also fetch CTUs. + + +```{r plot-city, eval = TRUE} +fetch_ctu_geo() %>% + map_council_continuous(.fill = ALAND) + + labs(title = "CTUs") ```