diff --git a/.Rbuildignore b/.Rbuildignore index 40a89ae..8e9d843 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -15,3 +15,4 @@ ^README.gfm-ascii_identifiers_files/.*$ ^appveyor\.yml$ ^codecov\.yml$ +^data-raw$ diff --git a/DESCRIPTION b/DESCRIPTION index 58c7e46..de58b6e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: statebins Type: Package -Title: Create 'U.S.' Uniform Square State Cartogram Heatmaps -Version: 2.0.0 -Date: 2017-11-14 +Title: Create United States Uniform Cartogram Heatmaps +Version: 1.4.0 +Date: 2020-07-08 Authors@R: c( person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-5670-2640")), @@ -16,16 +16,17 @@ Authors@R: c( comment = "Minor fix for NA handling") ) Maintainer: Bob Rudis -Description: Cartogram heatmaps are an alternative to choropleth maps for 'USA' States - and are based on work by the 'Washington Post' graphics department in their report +Description: The cartogram heatmaps generated by the included methods + are an alternative to choropleth maps for the United States + and are based on work by the Washington Post graphics department in their report on "The states most threatened by trade" - . + (). "State bins" preserve as much of the geographic placement of the states as - possible but has the look and feel of a traditional heatmap. Functions are + possible but have the look and feel of a traditional heatmap. Functions are provided that allow for use of a binned, discrete scale, a continuous scale or manually specified colors depending on what is needed for the underlying data. -URL: https://github.com/hrbrmstr/statebins -BugReports: https://github.com/hrbrmstr/statebins/issues +URL: https://gitlab.com/hrbrmstr/statebins +BugReports: https://gitlab.com/hrbrmstr/statebins/issues License: MIT + file LICENSE Encoding: UTF-8 Suggests: @@ -34,12 +35,12 @@ Suggests: RColorBrewer, covr Depends: - R (>= 3.2.0), + R (>= 3.5.0), Imports: ggplot2 (>= 2.2.1), scales (>= 0.5.0), grid -RoxygenNote: 6.1.1 +RoxygenNote: 7.1.0 Collate: 'aaa.R' 'geom-oscar.R' diff --git a/NEWS.md b/NEWS.md index 2603e49..1d799d7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +# statebins 1.4.0 +* New `state_tbl` dataset to make it easier to complete partial state data data frames + # statebins 1.3.0 * Added support for `VI`/`Virgin Islands` * Supports auto-computation of when to use light & dark label colors diff --git a/R/aaa.R b/R/aaa.R index e53ac10..0a81976 100644 --- a/R/aaa.R +++ b/R/aaa.R @@ -32,3 +32,9 @@ state_coords <- state_coords[order(state_coords$state),] b_state_coords <- state_coords colnames(b_state_coords) <- c("abbrev", "state", "x", "y") b_state_coords$y <- -b_state_coords$y + +#' "State" abbreviation to name data frame +#' +#' @name state_tbl +#' @docType data +NULL \ No newline at end of file diff --git a/R/statebins-package.R b/R/statebins-package.R index 8a2708c..fc1ac7c 100644 --- a/R/statebins-package.R +++ b/R/statebins-package.R @@ -1,4 +1,14 @@ -#' statebins is an alternative to choropleth maps for U.S. States +#' Create United States Uniform Cartogram Heatmaps +#' +#' The cartogram heatmaps generated by the included methods +#' are an alternative to choropleth maps for the United States +#' and are based on work by the Washington Post graphics department in their report +#' on "The states most threatened by trade" +#' (). +#' "State bins" preserve as much of the geographic placement of the states as +#' possible but have the look and feel of a traditional heatmap. Functions are +#' provided that allow for use of a binned, discrete scale, a continuous scale +#' or manually specified colors depending on what is needed for the underlying data. #' #' @md #' @name statebins-package diff --git a/README.Rmd b/README.Rmd index 24709b8..0f1b146 100644 --- a/README.Rmd +++ b/README.Rmd @@ -18,11 +18,13 @@ hrbrpkghelpr::yank_title_and_description() ## What's Inside The Tin -The following functions are implemented: +The following functions are implemented/datasets included: ```{r ingredients, results='asis', echo=FALSE, cache=FALSE} hrbrpkghelpr::describe_ingredients() ``` + +- `statebins`: (the original sole function in the package) Create a new ggplot-based "statebin" chart for USA states/territories ## Installation @@ -143,7 +145,7 @@ statebins(USArrests, value_col="Assault", name = "Assault", round=TRUE, ### Geom -```{r sb_facet, fig.width=17, fig.height=10} +```{r sb_facet, fig.width=20, fig.height=15} flu <- ili_weekly_activity_indicators(2017) ggplot(flu, aes(state=statename, fill=activity_level)) + diff --git a/README.md b/README.md index 0648107..d7d0089 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.re [![Signed by](https://img.shields.io/badge/Keybase-Verified-brightgreen.svg)](https://keybase.io/hrbrmstr) ![Signed commit -%](https://img.shields.io/badge/Signed_Commits-100%25-lightgrey.svg) +%](https://img.shields.io/badge/Signed_Commits-96%25-lightgrey.svg) [![Linux build Status](https://travis-ci.org/hrbrmstr/statebins.svg?branch=master)](https://travis-ci.org/hrbrmstr/statebins) [![Windows build @@ -17,36 +17,45 @@ checks](https://cranchecks.info/badges/worst/statebins)](https://cranchecks.info [![CRAN status](https://www.r-pkg.org/badges/version/statebins)](https://www.r-pkg.org/pkg/statebins) ![Minimal R -Version](https://img.shields.io/badge/R%3E%3D-3.2.0-blue.svg) +Version](https://img.shields.io/badge/R%3E%3D-3.5.0-blue.svg) ![License](https://img.shields.io/badge/License-MIT-blue.svg) # statebins -Create ‘U.S.’ Uniform Square State Cartogram Heatmaps +Create United States Uniform Cartogram Heatmaps ## Description -Cartogram heatmaps are an alternative to choropleth maps for ‘USA’ -States and are based on work by the ‘Washington Post’ graphics -department in their report on “The states most threatened by trade” -. +The cartogram heatmaps generated by the included methods are an +alternative to choropleth maps for the United States and are based on +work by the Washington Post graphics department in their report on “The +states most threatened by trade” +(). “State bins” preserve as much of the geographic placement of the states -as possible but has the look and feel of a traditional heatmap. +as possible but have the look and feel of a traditional heatmap. Functions are provided that allow for use of a binned, discrete scale, a continuous scale or manually specified colors depending on what is needed for the underlying data. ## What’s Inside The Tin -The following functions are implemented: +The following functions are implemented/datasets included: - `geom_statebins`: A statebins Geom + + - `state_tbl`: “State” abbreviation to name data frame + - `theme_statebins`: Base statebins theme + - `statebins`: (the original sole function in the package) Create a + new ggplot-based “statebin” chart for USA states/territories + ## Installation ``` r -install.packages("statebins", repos = "https://cinc.rud.is") +install.packages("statebins) # NOTE: CRAN version is 1.2.2 +# or +install.packages("statebins", repos = c("https://cinc.rud.is", "https://cloud.r-project.org/")) # or remotes::install_git("https://git.rud.is/hrbrmstr/statebins.git") # or @@ -78,7 +87,7 @@ library(tidyverse) # current verison packageVersion("statebins") -## [1] '2.0.0' +## [1] '1.4.0' ``` ### The original wapo data @@ -212,7 +221,7 @@ ggplot(flu, aes(state=statename, fill=activity_level)) + theme(plot.margin = margin(30,30,30,30)) ``` - + ### All the “states” diff --git a/data-raw/DATASET.R b/data-raw/DATASET.R new file mode 100644 index 0000000..4e42874 --- /dev/null +++ b/data-raw/DATASET.R @@ -0,0 +1,24 @@ +## code to prepare `DATASET` dataset goes here + +state_tbl <- structure(list(abbrev = c("AL", "AK", "AZ", "AR", "CA", "CO", + "CT", "DC", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", + "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", + "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", + "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY", + "PR", "VI", "NYC"), + state = c("Alabama", "Alaska", "Arizona", "Arkansas", + "California", "Colorado", "Connecticut", "District of Columbia", + "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", + "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", + "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", + "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", + "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", + "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", + "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", + "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming", + "Puerto Rico", "Virgin Islands", "New York City")), + .Names = c("abbrev", "state"), + class = "data.frame", row.names = c(NA, -54L)) + + +usethis::use_data(state_tbl, overwrite = TRUE) diff --git a/data/state_tbl.rda b/data/state_tbl.rda new file mode 100644 index 0000000..1f59f56 Binary files /dev/null and b/data/state_tbl.rda differ diff --git a/man/figures/README-all-1.png b/man/figures/README-all-1.png index c7540ce..dca466d 100644 Binary files a/man/figures/README-all-1.png and b/man/figures/README-all-1.png differ diff --git a/man/figures/README-continuous-1.png b/man/figures/README-continuous-1.png index 5ac48ca..2b5c46c 100644 Binary files a/man/figures/README-continuous-1.png and b/man/figures/README-continuous-1.png differ diff --git a/man/figures/README-continuous_noleg-1.png b/man/figures/README-continuous_noleg-1.png index 4724301..2255389 100644 Binary files a/man/figures/README-continuous_noleg-1.png and b/man/figures/README-continuous_noleg-1.png differ diff --git a/man/figures/README-fert-1.png b/man/figures/README-fert-1.png index 28d0ea5..d329248 100644 Binary files a/man/figures/README-fert-1.png and b/man/figures/README-fert-1.png differ diff --git a/man/figures/README-mort-1.png b/man/figures/README-mort-1.png index e91e6fa..f3035fa 100644 Binary files a/man/figures/README-mort-1.png and b/man/figures/README-mort-1.png differ diff --git a/man/figures/README-rounded-1.png b/man/figures/README-rounded-1.png index 0fa4929..0c11f10 100644 Binary files a/man/figures/README-rounded-1.png and b/man/figures/README-rounded-1.png differ diff --git a/man/figures/README-rounded2-1.png b/man/figures/README-rounded2-1.png index a910773..ef7eb52 100644 Binary files a/man/figures/README-rounded2-1.png and b/man/figures/README-rounded2-1.png differ diff --git a/man/figures/README-sb_facet-1.png b/man/figures/README-sb_facet-1.png index 3d83338..feeb617 100644 Binary files a/man/figures/README-sb_facet-1.png and b/man/figures/README-sb_facet-1.png differ diff --git a/man/geom_statebins.Rd b/man/geom_statebins.Rd index 60b8bfe..2a9ebde 100644 --- a/man/geom_statebins.Rd +++ b/man/geom_statebins.Rd @@ -5,12 +5,24 @@ \alias{geom_statebins} \alias{GeomStatebins} \title{A statebins Geom} -\format{An object of class \code{GeomStatebins} (inherits from \code{Geom}, \code{ggproto}, \code{gg}) of length 7.} +\format{ +An object of class \code{GeomStatebins} (inherits from \code{Geom}, \code{ggproto}, \code{gg}) of length 7. +} \usage{ -geom_statebins(mapping = NULL, data = NULL, border_col = "white", - border_size = 2, lbl_size = 3, dark_lbl = "black", - light_lbl = "white", radius = grid::unit(6, "pt"), ..., - na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) +geom_statebins( + mapping = NULL, + data = NULL, + border_col = "white", + border_size = 2, + lbl_size = 3, + dark_lbl = "black", + light_lbl = "white", + radius = grid::unit(6, "pt"), + ..., + na.rm = FALSE, + show.legend = NA, + inherit.aes = TRUE +) GeomStatebins } diff --git a/man/state_tbl.Rd b/man/state_tbl.Rd new file mode 100644 index 0000000..d41fbea --- /dev/null +++ b/man/state_tbl.Rd @@ -0,0 +1,9 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/aaa.R +\docType{data} +\name{state_tbl} +\alias{state_tbl} +\title{"State" abbreviation to name data frame} +\description{ +"State" abbreviation to name data frame +} diff --git a/man/statebins-package.Rd b/man/statebins-package.Rd index f858e66..a7caeef 100644 --- a/man/statebins-package.Rd +++ b/man/statebins-package.Rd @@ -3,9 +3,17 @@ \docType{package} \name{statebins-package} \alias{statebins-package} -\title{statebins is an alternative to choropleth maps for U.S. States} +\title{Create United States Uniform Cartogram Heatmaps} \description{ -statebins is an alternative to choropleth maps for U.S. States +The cartogram heatmaps generated by the included methods +are an alternative to choropleth maps for the United States +and are based on work by the Washington Post graphics department in their report +on "The states most threatened by trade" +(\url{http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/}). +"State bins" preserve as much of the geographic placement of the states as +possible but have the look and feel of a traditional heatmap. Functions are +provided that allow for use of a binned, discrete scale, a continuous scale +or manually specified colors depending on what is needed for the underlying data. } \author{ Bob Rudis (bob@rud.is) diff --git a/man/statebins.Rd b/man/statebins.Rd index e3601fe..6028f46 100644 --- a/man/statebins.Rd +++ b/man/statebins.Rd @@ -4,11 +4,21 @@ \alias{statebins} \title{Create a new ggplot-based "statebin" chart for USA states/territories} \usage{ -statebins(state_data, state_col = "state", value_col = "value", - dark_label = "black", light_label = "white", na_label = "white", - font_size = 3, state_border_col = "white", state_border_size = 2, - round = FALSE, radius = grid::unit(6, "pt"), - ggplot2_scale_function = ggplot2::scale_fill_distiller, ...) +statebins( + state_data, + state_col = "state", + value_col = "value", + dark_label = "black", + light_label = "white", + na_label = "white", + font_size = 3, + state_border_col = "white", + state_border_size = 2, + round = FALSE, + radius = grid::unit(6, "pt"), + ggplot2_scale_function = ggplot2::scale_fill_distiller, + ... +) } \arguments{ \item{state_data}{data frame of states and values to plot} diff --git a/man/theme_statebins.Rd b/man/theme_statebins.Rd index 3c06b2f..ea0b365 100644 --- a/man/theme_statebins.Rd +++ b/man/theme_statebins.Rd @@ -4,8 +4,7 @@ \alias{theme_statebins} \title{Base statebins theme} \usage{ -theme_statebins(legend_position = "bottom", base_size = 11, - base_family = "") +theme_statebins(legend_position = "bottom", base_size = 11, base_family = "") } \arguments{ \item{legend_position}{fills in \code{legend.position}}