From be45f0dc61307549be0372909370de2f114b7d18 Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Sat, 2 Mar 2024 17:52:34 -0500 Subject: [PATCH 1/4] Replace size with linewidth in plot_usmap documentation --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/plot-map.R | 6 +++--- man/plot_usmap.Rd | 6 +++--- man/usmap.Rd | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 025d2f1..137db93 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -28,6 +28,6 @@ Suggests: sf, testthat, vdiffr -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Roxygen: list(markdown = TRUE) VignetteBuilder: knitr diff --git a/NEWS.md b/NEWS.md index cd897ef..b810619 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,11 @@ # [unreleased] +### Improvements * Add citation information to README, see [Issue #86](https://github.com/pdil/usmap/issues/86). +### Bug Fixes +* Replace `size` with `linewidth` in `plot_usmap()` documentation, see [Issue #89](https://github.com/pdil/usmap/issues/89). + # usmap 0.7.0 Released Saturday, January 20, 2024. diff --git a/R/plot-map.R b/R/plot-map.R index 91610e8..454e782 100644 --- a/R/plot-map.R +++ b/R/plot-map.R @@ -19,11 +19,11 @@ #' for more color options. #' @param ... Other arguments to pass to [ggplot2::aes()]. These are #' often aesthetics, used to set an aesthetic to a fixed value, like \code{color = "red"} -#' or \code{size = 3}. They affect the appearance of the polygons used to render +#' or \code{linewidth = 3}. They affect the appearance of the polygons used to render #' the map (for example fill color, line color, line thickness, etc.). If any of -#' \code{color}/\code{colour}, \code{fill}, or \code{size} are not specified they +#' \code{color}/\code{colour}, \code{fill}, or \code{linewidth} are not specified they #' are set to their default values of \code{color="black"}, \code{fill="white"}, -#' and \code{size=0.4}. +#' and \code{linewidth=0.4}. #' #' @return A [ggplot2::ggplot] object that contains a basic #' US map with the described parameters. Since the result is a \code{ggplot} diff --git a/man/plot_usmap.Rd b/man/plot_usmap.Rd index 671466c..7b95e83 100644 --- a/man/plot_usmap.Rd +++ b/man/plot_usmap.Rd @@ -57,11 +57,11 @@ for more color options.} \item{...}{Other arguments to pass to \code{\link[ggplot2:aes]{ggplot2::aes()}}. These are often aesthetics, used to set an aesthetic to a fixed value, like \code{color = "red"} -or \code{size = 3}. They affect the appearance of the polygons used to render +or \code{linewidth = 3}. They affect the appearance of the polygons used to render the map (for example fill color, line color, line thickness, etc.). If any of -\code{color}/\code{colour}, \code{fill}, or \code{size} are not specified they +\code{color}/\code{colour}, \code{fill}, or \code{linewidth} are not specified they are set to their default values of \code{color="black"}, \code{fill="white"}, -and \code{size=0.4}.} +and \code{linewidth=0.4}.} } \value{ A \link[ggplot2:ggplot]{ggplot2::ggplot} object that contains a basic diff --git a/man/usmap.Rd b/man/usmap.Rd index 7a5e4ca..e7727e5 100644 --- a/man/usmap.Rd +++ b/man/usmap.Rd @@ -2,8 +2,8 @@ % Please edit documentation in R/usmap.R \docType{package} \name{usmap} -\alias{usmap} \alias{usmap-package} +\alias{usmap} \title{usmap: US maps including Alaska and Hawaii} \description{ It is usually difficult or inconvenient to create US maps that From 68963d6f08ae03ba89fe3270cfdd0dafd3dd4f3d Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Wed, 6 Mar 2024 21:52:35 -0500 Subject: [PATCH 2/4] Update theme_map() legend to work with ggplot2 v3.5.0 --- DESCRIPTION | 2 +- NEWS.md | 1 + R/plot-map.R | 4 ++-- README.md | 11 ++++++----- ...le-data-state-map-with-custom-linewidth.svg | 18 +++++++++--------- ...state-population-map-with-blue-outlines.svg | 14 +++++++------- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 137db93..57ba3ed 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,7 +19,7 @@ Imports: usmapdata (>= 0.2.0) Suggests: covr, - ggplot2, + ggplot2 (>= 3.5.0), ggrepel, knitr, proto, diff --git a/NEWS.md b/NEWS.md index b810619..39bda6b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ ### Improvements * Add citation information to README, see [Issue #86](https://github.com/pdil/usmap/issues/86). +* Update map theme to work with new legend behavior in [ggplot2 v3.5.0](https://www.tidyverse.org/blog/2024/02/ggplot2-3-5-0-legends/#placement). ### Bug Fixes * Replace `size` with `linewidth` in `plot_usmap()` documentation, see [Issue #89](https://github.com/pdil/usmap/issues/89). diff --git a/R/plot-map.R b/R/plot-map.R index 454e782..49862f1 100644 --- a/R/plot-map.R +++ b/R/plot-map.R @@ -174,6 +174,6 @@ theme_map <- function(base_size = 9, base_family = "") { panel.grid = element_blank, panel.spacing = unit(0, "lines"), plot.background = element_blank, - legend.justification = c(0, 0), - legend.position = c(0, 0)) + legend.position = "inside", + legend.justification.inside = c(0, 0)) } diff --git a/README.md b/README.md index e9c1658..1b87d1e 100644 --- a/README.md +++ b/README.md @@ -267,19 +267,20 @@ required!), you may do so in the following way: ``` r citation("usmap") +#> Warning in citation("usmap"): could not determine year for 'usmap' from package +#> DESCRIPTION file #> To cite package 'usmap' in publications use: #> -#> Di Lorenzo P (2024). _usmap: US Maps Including Alaska and Hawaii_. R -#> package version 0.7.0, . +#> Di Lorenzo P (????). _usmap: US Maps Including Alaska and Hawaii_. R +#> package version 0.7.0.9999, . #> #> A BibTeX entry for LaTeX users is #> #> @Manual{, #> title = {usmap: US Maps Including Alaska and Hawaii}, #> author = {Paolo {Di Lorenzo}}, -#> year = {2024}, -#> note = {R package version 0.7.0}, -#> url = {https://CRAN.R-project.org/package=usmap}, +#> note = {R package version 0.7.0.9999}, +#> url = {https://usmap.dev}, #> } ``` diff --git a/tests/testthat/_snaps/plot/example-data-state-map-with-custom-linewidth.svg b/tests/testthat/_snaps/plot/example-data-state-map-with-custom-linewidth.svg index 03de562..6de3a73 100644 --- a/tests/testthat/_snaps/plot/example-data-state-map-with-custom-linewidth.svg +++ b/tests/testthat/_snaps/plot/example-data-state-map-with-custom-linewidth.svg @@ -165,20 +165,20 @@ +values + + + + + + + + 5 6 7 8 -values - - - - - - - - Example data state map with custom linewidth diff --git a/tests/testthat/_snaps/plot/state-population-map-with-blue-outlines.svg b/tests/testthat/_snaps/plot/state-population-map-with-blue-outlines.svg index 43da2f8..ccd7cdd 100644 --- a/tests/testthat/_snaps/plot/state-population-map-with-blue-outlines.svg +++ b/tests/testthat/_snaps/plot/state-population-map-with-blue-outlines.svg @@ -165,17 +165,17 @@ +pop_2015 + + + + + + 1e+07 2e+07 3e+07 -pop_2015 - - - - - - State population map with blue outlines From 5dfd2acf67edc89169a6237a63cbb58e499fba92 Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Wed, 6 Mar 2024 21:59:21 -0500 Subject: [PATCH 3/4] Update to testthat 3rd edition --- DESCRIPTION | 3 +- tests/testthat.R | 8 +++++ tests/testthat/test-fips-info.R | 29 ++++++++-------- tests/testthat/test-fips.R | 1 - tests/testthat/test-join-data.R | 1 - tests/testthat/test-plot.R | 59 ++++++++++++++++----------------- tests/testthat/test-transform.R | 1 - tests/testthat/test-usmap.R | 1 - 8 files changed, 55 insertions(+), 48 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 57ba3ed..3a5e180 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -26,8 +26,9 @@ Suggests: rmarkdown, scales, sf, - testthat, + testthat (>= 3.0.0), vdiffr RoxygenNote: 7.3.1 Roxygen: list(markdown = TRUE) VignetteBuilder: knitr +Config/testthat/edition: 3 diff --git a/tests/testthat.R b/tests/testthat.R index db50218..ff30202 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,3 +1,11 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + library(testthat) library(usmap) diff --git a/tests/testthat/test-fips-info.R b/tests/testthat/test-fips-info.R index 4d00a2f..a71af6b 100644 --- a/tests/testthat/test-fips-info.R +++ b/tests/testthat/test-fips-info.R @@ -1,4 +1,3 @@ -context("Retrieving FIPS code info") test_that("all states returned when no FIPS specified", { expect_equal(fips_info()$fips, fips()) @@ -12,8 +11,8 @@ test_that("returns correct state FIPS information", { stringsAsFactors = FALSE ) - expect_equivalent(fips_info(c(2, 34, 2)), ak_result) - expect_equivalent(fips_info(c("02", "34", "02")), ak_result) + expect_equal(fips_info(c(2, 34, 2)), ak_result, ignore_attr = TRUE) + expect_equal(fips_info(c("02", "34", "02")), ak_result, ignore_attr = TRUE) ak_result_sorted <- data.frame( abbr = c("AK", "NJ"), @@ -22,10 +21,12 @@ test_that("returns correct state FIPS information", { stringsAsFactors = FALSE ) - expect_equivalent(fips_info(c(2, 34, 2), sortAndRemoveDuplicates = TRUE), - ak_result_sorted) - expect_equivalent(fips_info(c("02", "34", "02"), sortAndRemoveDuplicates = TRUE), - ak_result_sorted) + expect_equal(fips_info(c(2, 34, 2), sortAndRemoveDuplicates = TRUE), + ak_result_sorted, + ignore_attr = TRUE) + expect_equal(fips_info(c("02", "34", "02"), sortAndRemoveDuplicates = TRUE), + ak_result_sorted, + ignore_attr = TRUE) }) test_that("returns correct county FIPS information", { @@ -38,8 +39,8 @@ test_that("returns correct county FIPS information", { stringsAsFactors = FALSE ) - expect_equivalent(fips_info(c(2020, 2016, 2020)), ak_result) - expect_equivalent(fips_info(c("02020", "02016", "02020")), ak_result) + expect_equal(fips_info(c(2020, 2016, 2020)), ak_result, ignore_attr = TRUE) + expect_equal(fips_info(c("02020", "02016", "02020")), ak_result, ignore_attr = TRUE) ak_result_sorted <- data.frame( full = rep("Alaska", 2), @@ -49,10 +50,12 @@ test_that("returns correct county FIPS information", { stringsAsFactors = FALSE ) - expect_equivalent(fips_info(c(2020, 2016, 2020), sortAndRemoveDuplicates = TRUE), - ak_result_sorted) - expect_equivalent(fips_info(c("02020", "02016", "02020"), sortAndRemoveDuplicates = TRUE), - ak_result_sorted) + expect_equal(fips_info(c(2020, 2016, 2020), sortAndRemoveDuplicates = TRUE), + ak_result_sorted, + ignore_attr = TRUE) + expect_equal(fips_info(c("02020", "02016", "02020"), sortAndRemoveDuplicates = TRUE), + ak_result_sorted, + ignore_attr = TRUE) }) # non-existent yet valid means a FIPS such as "03", which falls diff --git a/tests/testthat/test-fips.R b/tests/testthat/test-fips.R index 16e4130..fbbaa55 100644 --- a/tests/testthat/test-fips.R +++ b/tests/testthat/test-fips.R @@ -1,4 +1,3 @@ -context("Retrieving FIPS codes") test_that("all FIPS codes returned when no state specified", { expect_equal(fips(), diff --git a/tests/testthat/test-join-data.R b/tests/testthat/test-join-data.R index 087a600..e1f969b 100644 --- a/tests/testthat/test-join-data.R +++ b/tests/testthat/test-join-data.R @@ -1,4 +1,3 @@ -context("Joining state and county data to map") state_data <- data.frame(fips = c("01", "02", "04"), values = c(3, 5, 10)) county_data <- data.frame(fips = c("01001", "01003", "01005"), values = c(3, 5, 10)) diff --git a/tests/testthat/test-plot.R b/tests/testthat/test-plot.R index 864eaf0..d4edd1c 100644 --- a/tests/testthat/test-plot.R +++ b/tests/testthat/test-plot.R @@ -1,4 +1,3 @@ -context("Plotting US maps") test_that("dependencies are verified", { expect_package_error("ggplot2", plot_usmap()) @@ -20,13 +19,13 @@ u <- plot_usmap(include = .new_england, exclude = "ME", labels = TRUE) v <- plot_usmap("state", labels = TRUE) test_that("ggplot object is returned", { - expect_is(p, "ggplot") - expect_is(q, "ggplot") - expect_is(r, "ggplot") - expect_is(s, "ggplot") - expect_is(t, "ggplot") - expect_is(u, "ggplot") - expect_is(v, "ggplot") + expect_s3_class(p, "ggplot") + expect_s3_class(q, "ggplot") + expect_s3_class(r, "ggplot") + expect_s3_class(s, "ggplot") + expect_s3_class(t, "ggplot") + expect_s3_class(u, "ggplot") + expect_s3_class(v, "ggplot") }) test_that("no warnings are produced", { @@ -80,60 +79,60 @@ test_that("plots are stable", { }) test_that("layer parameters are correct", { - expect_is(p$layers[[1]], "ggproto") - expect_is(p$layers[[1]]$geom, "GeomSf") + expect_s3_class(p$layers[[1]], "ggproto") + expect_s3_class(p$layers[[1]]$geom, "GeomSf") expect_equal(as.character(p$layers[[1]]$aes_params$colour), "black") expect_equal(as.character(p$layers[[1]]$aes_params$fill), "red") expect_equal(p$layers[[1]]$aes_params$linewidth, 0.4) - expect_is(q$layers[[1]], "ggproto") - expect_is(q$layers[[1]]$geom, "GeomSf") + expect_s3_class(q$layers[[1]], "ggproto") + expect_s3_class(q$layers[[1]]$geom, "GeomSf") expect_equal(deparse(q$layers[[1]]$mapping$fill), "~.data[[\"pop_2015\"]]") expect_equal(as.character(q$layers[[1]]$aes_params$colour), "blue") expect_equal(q$layers[[1]]$aes_params$linewidth, 0.4) - expect_is(r$layers[[1]], "ggproto") - expect_is(r$layers[[1]]$geom, "GeomSf") + expect_s3_class(r$layers[[1]], "ggproto") + expect_s3_class(r$layers[[1]]$geom, "GeomSf") expect_equal(deparse(r$layers[[1]]$mapping$fill), "~.data[[\"values\"]]") expect_equal(as.character(r$layers[[1]]$aes_params$colour), "black") expect_equal(r$layers[[1]]$aes_params$linewidth, 0.8) - expect_is(s$layers[[1]], "ggproto") - expect_is(s$layers[[1]]$geom, "GeomSf") + expect_s3_class(s$layers[[1]], "ggproto") + expect_s3_class(s$layers[[1]]$geom, "GeomSf") expect_equal(as.character(s$layers[[1]]$aes_params$fill), "white") expect_equal(as.character(s$layers[[1]]$aes_params$colour), "black") expect_equal(s$layers[[1]]$aes_params$linewidth, 0.4) - expect_is(s$layers[[2]], "ggproto") - expect_is(s$layers[[2]]$geom, "GeomText") + expect_s3_class(s$layers[[2]], "ggproto") + expect_s3_class(s$layers[[2]]$geom, "GeomText") expect_equal(deparse(s$layers[[2]]$mapping$label), "~.data$abbr") expect_equal(as.character(s$layers[[2]]$aes_params$colour), "blue") - expect_is(t$layers[[1]], "ggproto") - expect_is(s$layers[[1]]$geom, "GeomSf") + expect_s3_class(t$layers[[1]], "ggproto") + expect_s3_class(s$layers[[1]]$geom, "GeomSf") expect_equal(as.character(t$layers[[1]]$aes_params$fill), "yellow") expect_equal(as.character(t$layers[[1]]$aes_params$colour), "black") expect_equal(t$layers[[1]]$aes_params$linewidth, 0.6) - expect_is(t$layers[[2]], "ggproto") - expect_is(t$layers[[2]]$geom, "GeomText") + expect_s3_class(t$layers[[2]], "ggproto") + expect_s3_class(t$layers[[2]]$geom, "GeomText") expect_equal(deparse(t$layers[[2]]$mapping$label), "~sub(\" County\", \"\", .data$county)") - expect_is(u$layers[[1]], "ggproto") - expect_is(u$layers[[1]]$geom, "GeomSf") + expect_s3_class(u$layers[[1]], "ggproto") + expect_s3_class(u$layers[[1]]$geom, "GeomSf") expect_equal(as.character(u$layers[[1]]$aes_params$fill), "white") expect_equal(as.character(u$layers[[1]]$aes_params$colour), "black") expect_equal(u$layers[[1]]$aes_params$linewidth, 0.4) - expect_is(u$layers[[2]], "ggproto") - expect_is(u$layers[[2]]$geom, "GeomText") + expect_s3_class(u$layers[[2]], "ggproto") + expect_s3_class(u$layers[[2]]$geom, "GeomText") expect_equal(deparse(u$layers[[2]]$mapping$label), "~.data$abbr") - expect_is(v$layers[[1]], "ggproto") - expect_is(v$layers[[1]]$geom, "GeomSf") + expect_s3_class(v$layers[[1]], "ggproto") + expect_s3_class(v$layers[[1]]$geom, "GeomSf") expect_equal(as.character(v$layers[[1]]$aes_params$fill), "white") expect_equal(as.character(v$layers[[1]]$aes_params$colour), "black") expect_equal(v$layers[[1]]$aes_params$linewidth, 0.4) - expect_is(v$layers[[2]], "ggproto") - expect_is(v$layers[[2]]$geom, "GeomText") + expect_s3_class(v$layers[[2]], "ggproto") + expect_s3_class(v$layers[[2]]$geom, "GeomText") expect_equal(deparse(v$layers[[2]]$mapping$label), "~.data$abbr") }) diff --git a/tests/testthat/test-transform.R b/tests/testthat/test-transform.R index c3e84df..e98748b 100644 --- a/tests/testthat/test-transform.R +++ b/tests/testthat/test-transform.R @@ -1,4 +1,3 @@ -context("Transforming coordinate data frames") test_that("data frame with AK and HI points is transformed", { data <- data.frame( diff --git a/tests/testthat/test-usmap.R b/tests/testthat/test-usmap.R index ed8cdfa..aae6bf6 100644 --- a/tests/testthat/test-usmap.R +++ b/tests/testthat/test-usmap.R @@ -1,4 +1,3 @@ -context("Retrieving US map data") test_that("state data frame is returned", { data <- us_map() From ab2039867b93c919bc52a0351b2a54ace969d9b6 Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Wed, 6 Mar 2024 22:06:08 -0500 Subject: [PATCH 4/4] Revert README.md --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1b87d1e..e9c1658 100644 --- a/README.md +++ b/README.md @@ -267,20 +267,19 @@ required!), you may do so in the following way: ``` r citation("usmap") -#> Warning in citation("usmap"): could not determine year for 'usmap' from package -#> DESCRIPTION file #> To cite package 'usmap' in publications use: #> -#> Di Lorenzo P (????). _usmap: US Maps Including Alaska and Hawaii_. R -#> package version 0.7.0.9999, . +#> Di Lorenzo P (2024). _usmap: US Maps Including Alaska and Hawaii_. R +#> package version 0.7.0, . #> #> A BibTeX entry for LaTeX users is #> #> @Manual{, #> title = {usmap: US Maps Including Alaska and Hawaii}, #> author = {Paolo {Di Lorenzo}}, -#> note = {R package version 0.7.0.9999}, -#> url = {https://usmap.dev}, +#> year = {2024}, +#> note = {R package version 0.7.0}, +#> url = {https://CRAN.R-project.org/package=usmap}, #> } ```