Skip to content

Commit

Permalink
Add visual snapshot tests (#82)
Browse files Browse the repository at this point in the history
* Added `vdiffr`-based tests for `plot_usmap()`
* Renamed `rivers` data set to `usrivers` to avoid clash with
`datasets::rivers` package
* Fixed missing `citypop.xlsx` file and rebuilt all data sets

resolves #80
  • Loading branch information
pdil committed Jan 17, 2024
2 parents 4acba1e + 0918cc8 commit 01f7420
Show file tree
Hide file tree
Showing 76 changed files with 1,059 additions and 33 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Expand Up @@ -4,7 +4,7 @@ Title: US Maps Including Alaska and Hawaii
Description: Obtain United States map data frames of varying region types (e.g. county,
state). The map data frames include Alaska and Hawaii conveniently placed to the
bottom left, as they appear in most maps of the US. Convenience functions for plotting
choropleths and working with FIPS codes are also provided.
choropleths, drawing map features, and working with FIPS codes are also provided.
Authors@R: person("Paolo", "Di Lorenzo", email = "dilorenzo@hey.com", role = c("aut", "cre"))
Depends:
R (>= 3.5.0)
Expand All @@ -26,7 +26,8 @@ Suggests:
rmarkdown,
scales,
sf,
testthat
testthat,
vdiffr
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
VignetteBuilder: knitr
10 changes: 7 additions & 3 deletions NEWS.md
@@ -1,4 +1,4 @@
# usmap 0.6.4.9999
# [unreleased]

### Improvements
* Migrate to new `usmapdata 0.2.0` `sf`-based map data files.
Expand All @@ -10,11 +10,15 @@
* The output data frame now replaces the `lat`/`lon` columns with a single `geometry` column with the transformed points and can be plotted using `ggplot2::geom_sf()`.
* Review the included examples and `advanced-mapping` vignette for more details.
* `usmap_transform()` now accepts `sf` objects and automatically transforms its `geometry` column to the projection used by this package.
* It is now possible to add any geographical features to the plotted map such as rivers, roads, topographical data, etc. using `usmap_transform()` before plotting with `ggplot2::geom_sf()`.
* It is now possible to add any geographical features to the plotted map such as rivers, roads, topographical data, etc. using `usmap_transform()` before plotting with `ggplot2::geom_sf()`, see [Issue #12](https://github.com/pdil/usmap/issues/12).
* See the provided vignettes and examples for more information.
* Input can now also be in any coordinate reference system, if it is not standard longitude/latitude, it can be specified with the `crs` parameter.
* Add `rivers` dataset featuring major US rivers.
* Add `usrivers` dataset featuring major US rivers.
* The dataset is provided in an `sf` object and is ready to be transformed with `usmap_transform()` and plotted with `plot_usmap() + ggplot2::geom_sf()`.
* Add visual snapshot tests for more resilient plots, see [Issue #80](https://github.com/pdil/usmap/issues/80).

### Bug Fixes
* `plot_usmap()` warnings have been cleaned up, including a defunct warning that didn't make sense.

### Removed
* `output_names` is no longer required as a parameter to `usmap_transform()`.
Expand Down
8 changes: 4 additions & 4 deletions R/datasets.R → R/data.R
Expand Up @@ -164,12 +164,12 @@

#' US Major Rivers (2010)
#'
#' @description Major rivers in United States.\cr\cr
#' @description Major rivers in the United States.\cr\cr
#' The data is can be transformed with [usmap::usmap_transform].
#' Once the `Shape` strings are transformed, it can be added to
#' [plot_usmap] using a [ggplot2::geom_sf] layer.
#'
#' @usage data(rivers)
#' @usage data(usrivers)
#'
#' @details
#' \itemize{
Expand All @@ -180,7 +180,7 @@
#' \item \code{Shape} The MULTILINESTRING features depicting the river, for plotting.
#' }
#'
#' @name rivers
#' @name usrivers
#' @format A simple features (sf) data frame with 55 rows and 5 variables.
#' @docType data
#' @references
Expand All @@ -190,4 +190,4 @@
#' Digital Chart of the World (DCW), U.S. National Geospatial-Intelligence Agency (NGA); i-cubed
#' }
#' @keywords data
"rivers"
"usrivers"
12 changes: 7 additions & 5 deletions README.md
Expand Up @@ -6,7 +6,7 @@
View code used to generate these plots: [resources/examples.R](https://github.com/pdil/usmap/blob/master/resources/examples.R)

## Purpose
Typically in R it is difficult to create nice US [choropleths](https://en.wikipedia.org/wiki/Choropleth_map) that include Alaska and Hawaii. The functions presented here attempt to elegantly solve this problem by manually moving these states to a new location and providing a fortified data frame for mapping and visualization. This allows the user to easily add data to color the map.
Typically in R it is difficult to create nice US [choropleths](https://en.wikipedia.org/wiki/Choropleth_map) that include Alaska and Hawaii. The functions presented here attempt to elegantly solve this problem by manually moving these states to a new location and providing a simple features ([`sf`](https://github.com/r-spatial/sf)) object for mapping and visualization. This allows the user to easily add visual data or features to the US map.

## Shape Files
The shape files that we use to plot the maps in R are located in the [`usmapdata`](https://github.com/pdil/usmapdata) package. These are generated from the [US Census Bureau cartographic boundary files](https://www.census.gov/geographies/mapping-files/time-series/geo/cartographic-boundary.html). Maps at both the state and county levels are included for convenience.
Expand All @@ -21,18 +21,20 @@ The shape files that we use to plot the maps in R are located in the [`usmapdata
| January 29, 2017 | 0.1.0 | 2015 | [🔗](https://www.census.gov/geographies/mapping-files/time-series/geo/carto-boundary-file.2015.html) |

## Installation
To install from CRAN _(recommended)_, run the following code in an R console:
📦 To install from CRAN (recommended), run the following code in an R console:
```r
install.packages("usmap")
```

### Developer Build
⚠️ The developer build may be unstable and not function correctly, use with caution.

To install the package from this repository, run the following code in an R console:
```r
# install.package("devtools")
devtools::install_github("pdil/usmap")
```
Installing using `devtools::install_github` will provide the most recent developer build of `usmap`.

⚠️ The developer build may be unstable and not function correctly, use with caution.
This method will provide the most recent developer build of `usmap`.

To begin using `usmap`, import the package using the `library` command:
```r
Expand Down
Binary file added data-raw/citypop.xlsx
Binary file not shown.
3 changes: 0 additions & 3 deletions data-raw/rivers.R

This file was deleted.

3 changes: 3 additions & 0 deletions data-raw/usrivers.R
@@ -0,0 +1,3 @@

usrivers <- sf::st_read("data-raw/usrivers.gdb")
usethis::use_data(usrivers, overwrite = TRUE)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file modified data/citypop.rda
Binary file not shown.
Binary file modified data/countypop.rda
Binary file not shown.
Binary file modified data/countypov.rda
Binary file not shown.
Binary file modified data/earthquakes.rda
Binary file not shown.
Binary file removed data/rivers.rda
Binary file not shown.
Binary file modified data/statepop.rda
Binary file not shown.
Binary file modified data/statepov.rda
Binary file not shown.
Binary file added data/usrivers.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion man/citypop.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/countypop.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/countypov.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/earthquakes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/statepop.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/statepov.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions man/rivers.Rd → man/usrivers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 01f7420

Please sign in to comment.