From 17b748795733e45f1e815c4a7cb1a70caed42898 Mon Sep 17 00:00:00 2001 From: Lincoln Mullen Date: Thu, 29 Mar 2018 14:25:50 -0400 Subject: [PATCH] Prep for 0.3.1 release --- DESCRIPTION | 4 +- NEWS.md | 1 + R/state_plane.R | 22 ++--- cran-comments.md | 12 ++- man/state_plane.Rd | 22 ++--- vignettes/usaboundaries-sample-analysis.Rmd | 91 ++++++++++++--------- 6 files changed, 85 insertions(+), 67 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 19c20b9..c5c7f17 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: USAboundaries Type: Package Title: Historical and Contemporary Boundaries of the United States of America -Version: 0.3.0.9000 -Date: 2017-07-05 +Version: 0.3.1 +Date: 2018-03-29 Authors@R: c(person("Lincoln", "Mullen", email = "lincoln@lincolnmullen.com", role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index cf3d6c4..21437f8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ - Additions and clarifications to documentation following @AndySouth's suggestions for JOSS peer review (#38). - `us_cities()` now returns an `sf` object rather than a data frame (#36). - `us_cities()` gains a `states` argument to match other functions in the package (#35). +- Citation to JOSS paper. # USAboundaries 0.3.0 diff --git a/R/state_plane.R b/R/state_plane.R index 33af5ec..434e294 100644 --- a/R/state_plane.R +++ b/R/state_plane.R @@ -17,17 +17,19 @@ #' projection data frame, see \code{\link{state_proj}}. #' #' @examples -#' state_plane(state = "MA", type = "epsg") -#' state_plane(state = "MA", type = "proj4") -#' state_plane(state = "MA", plane_id = "island", type = "epsg") -#' state_plane(state = "MA", plane_id = "island", type = "proj4") +#' if (require(USAboundariesData)) { +#' state_plane(state = "MA", type = "epsg") +#' state_plane(state = "MA", type = "proj4") +#' state_plane(state = "MA", plane_id = "island", type = "epsg") +#' state_plane(state = "MA", plane_id = "island", type = "proj4") #' -#' # Show the difference made by a state plane projection -#' if (require(sf)) { -#' va <- us_states(states = "VA", resolution = "high") -#' plot(st_geometry(va), graticule = TRUE) -#' va <- st_transform(va, state_plane("VA")) -#' plot(st_geometry(va), graticule = TRUE) +#' # Show the difference made by a state plane projection +#' if (require(sf)) { +#' va <- us_states(states = "VA", resolution = "high") +#' plot(st_geometry(va), graticule = TRUE) +#' va <- st_transform(va, state_plane("VA")) +#' plot(st_geometry(va), graticule = TRUE) +#' } #' } #' #' @export diff --git a/cran-comments.md b/cran-comments.md index 1a5da5c..c1c4d66 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,16 +1,14 @@ -This is an updated version of the 'USAboundaries' package from version 0.2.0 to version 0.3.0. - -Following a suggestion from CRAN maintainers, documentation links to the USAboundariesData package have been removed. +This is a minor release of the 'USAboundaries' package. It makes all of the included data have a consistent output format. ## Test environments -* local OS X install, R 3.4.0 -* ubuntu 14.04 (on travis-ci), R-devel, R-current, R-oldrel -* win-builder (R-devel and R-release) +* local OS X install, R-release +* Travis-CI, R-devel, R-release, R-oldrel +* ubuntu 14.04 (on travis-ci), R-devel, R-release, R-oldrel +* win-builder (R-devel) ## R CMD check results There were no ERRORs or WARNINGs. There are several NOTEs about suggested package in an additional repository which adds extra data. This 'USAboundariesData' package is provided in the rOpenSci CRAN-style repository, and it is installed on user request. - diff --git a/man/state_plane.Rd b/man/state_plane.Rd index 3ceaa65..852d225 100644 --- a/man/state_plane.Rd +++ b/man/state_plane.Rd @@ -25,17 +25,19 @@ Get EPSG codes or PROJ.4 codes for projections from the Plane Coordinate System}. } \examples{ -state_plane(state = "MA", type = "epsg") -state_plane(state = "MA", type = "proj4") -state_plane(state = "MA", plane_id = "island", type = "epsg") -state_plane(state = "MA", plane_id = "island", type = "proj4") +if (require(USAboundariesData)) { + state_plane(state = "MA", type = "epsg") + state_plane(state = "MA", type = "proj4") + state_plane(state = "MA", plane_id = "island", type = "epsg") + state_plane(state = "MA", plane_id = "island", type = "proj4") -# Show the difference made by a state plane projection -if (require(sf)) { - va <- us_states(states = "VA", resolution = "high") - plot(st_geometry(va), graticule = TRUE) - va <- st_transform(va, state_plane("VA")) - plot(st_geometry(va), graticule = TRUE) + # Show the difference made by a state plane projection + if (require(sf)) { + va <- us_states(states = "VA", resolution = "high") + plot(st_geometry(va), graticule = TRUE) + va <- st_transform(va, state_plane("VA")) + plot(st_geometry(va), graticule = TRUE) + } } } diff --git a/vignettes/usaboundaries-sample-analysis.Rmd b/vignettes/usaboundaries-sample-analysis.Rmd index 77f8c67..27fa8a8 100644 --- a/vignettes/usaboundaries-sample-analysis.Rmd +++ b/vignettes/usaboundaries-sample-analysis.Rmd @@ -24,49 +24,63 @@ library(USAboundaries) library(dplyr) library(sf) library(leaflet) + +# Check that USAboundariesData is available, since it is not on CRAN +avail <- requireNamespace("USAboundariesData", quietly = TRUE) ``` We can load the voting data for the 115th Congress into `md_votes`. We use this package to get the contemporary (2016) boundaries for Congressional districts in Maryland. They are returned as an `sf` object from the [sf](https://github.com/r-spatial/sf/) package. ```{r} -md_votes <- read.csv(system.file("extdata", "md-115.csv", package = "USAboundaries"), - colClasses = c("character", "integer", "character", "integer", - "character", "integer", "integer", "integer", - "integer", "integer", "integer", "numeric", - "numeric", "numeric", "numeric", "numeric")) -md_districts <- us_congressional(states = "MD") +if (avail) { + md_votes <- read.csv(system.file("extdata", "md-115.csv", + package = "USAboundaries"), + colClasses = c("character", "integer", "character", "integer", + "character", "integer", "integer", "integer", + "integer", "integer", "integer", "numeric", + "numeric", "numeric", "numeric", "numeric")) + md_districts <- us_congressional(states = "MD") +} ``` In order to map the data, we have to join the voting data to the spatial data. ```{r} -md_115 <- md_districts %>% - left_join(md_votes, by = c("cd115fp" = "district")) +if (avail) { + md_115 <- md_districts %>% + left_join(md_votes, by = c("cd115fp" = "district")) +} ``` The data has the percentage of votes for Democrats and Republicans. We are going to map the margin that Republicans had over an even vote, so that we can see both the Democrat and Republican results. For a more careful analysis we would have to take account of third parties and write-in votes, but this will serve our purpose. ```{r} -md_115$margin_percent <- md_115$percentage_republican - 0.5 +if (avail) { + md_115$margin_percent <- md_115$percentage_republican - 0.5 +} ``` We create a color palette to turn the margin of victory into red and blue colors. ```{r} -palette <- colorBin("RdBu", domain = c(-0.3, 0.3), bins = 7, reverse = TRUE) +if (avail) { + palette <- colorBin("RdBu", domain = c(-0.3, 0.3), bins = 7, reverse = TRUE) +} ``` We can use the [leaflet](https://rstudio.github.io/leaflet/) package to make the map. ```{r} -leaflet(md_115) %>% - addTiles() %>% - addPolygons(color = "black", - opacity = 1, - weight = 1, - fillColor = ~palette(margin_percent), - fillOpacity = 1, - label = ~paste0("District: ", cd115fp)) +if (avail) { + leaflet(md_115) %>% + addTiles() %>% + addPolygons(color = "black", + opacity = 1, + weight = 1, + fillColor = ~palette(margin_percent), + fillOpacity = 1, + label = ~paste0("District: ", cd115fp)) +} ``` We can do the same analysis for the 3rd Congress, thanks to the historical data included in the package. In this case, we will have to map counties rather than Congressional districts. The parties of interest are the Federalists and the Democratic-Republicans. @@ -74,29 +88,30 @@ We can do the same analysis for the 3rd Congress, thanks to the historical data We start by loading and joining the data. ```{r} -md_03_votes <- read.csv(system.file("extdata", "md-003.csv", package = "USAboundaries"), - stringsAsFactors = FALSE) -md_03_districts <- us_counties(map_date = "1792-10-01", - resolution = "high", states = "MD") -md_003 <- md_03_districts %>% - left_join(md_03_votes, by = c("id" = "county_ahcb")) -md_003$margin_percent <- md_003$federalist_percentage - 0.5 +if (avail) { + md_03_votes <- read.csv(system.file("extdata", "md-003.csv", + package = "USAboundaries"), + stringsAsFactors = FALSE) + md_03_districts <- us_counties(map_date = "1792-10-01", + resolution = "high", states = "MD") + md_003 <- md_03_districts %>% + left_join(md_03_votes, by = c("id" = "county_ahcb")) + md_003$margin_percent <- md_003$federalist_percentage - 0.5 +} ``` Then we create a new palette function and make the map. ```{r} -palette_03 <- colorBin("PRGn", domain = c(-0.5, 0.5), bins = 9) -leaflet(md_003) %>% - addTiles() %>% - addPolygons(color = "black", - opacity = 1, - weight = 1, - fillColor = ~palette_03(margin_percent), - fillOpacity = 1, - label = ~paste0("County: ", name)) +if (avail) { + palette_03 <- colorBin("PRGn", domain = c(-0.5, 0.5), bins = 9) + leaflet(md_003) %>% + addTiles() %>% + addPolygons(color = "black", + opacity = 1, + weight = 1, + fillColor = ~palette_03(margin_percent), + fillOpacity = 1, + label = ~paste0("County: ", name)) +} ``` - - - -