diff --git a/DESCRIPTION b/DESCRIPTION
index 025d2f1..3a5e180 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -19,15 +19,16 @@ Imports:
usmapdata (>= 0.2.0)
Suggests:
covr,
- ggplot2,
+ ggplot2 (>= 3.5.0),
ggrepel,
knitr,
proto,
rmarkdown,
scales,
sf,
- testthat,
+ testthat (>= 3.0.0),
vdiffr
-RoxygenNote: 7.2.3
+RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
VignetteBuilder: knitr
+Config/testthat/edition: 3
diff --git a/NEWS.md b/NEWS.md
index cd897ef..39bda6b 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,6 +1,11 @@
# [unreleased]
+### 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).
# usmap 0.7.0
Released Saturday, January 20, 2024.
diff --git a/R/plot-map.R b/R/plot-map.R
index 91610e8..49862f1 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}
@@ -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/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
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/_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
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()