diff --git a/.Rbuildignore b/.Rbuildignore index 158f97e..40a89ae 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -13,3 +13,5 @@ ^README.gfm-ascii_identifiers_files$ ^README.gfm-ascii_identifiers_files/$ ^README.gfm-ascii_identifiers_files/.*$ +^appveyor\.yml$ +^codecov\.yml$ diff --git a/.travis.yml b/.travis.yml index 8d139ac..50534d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ -# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r - language: R sudo: false cache: packages + +after_success: + - Rscript -e 'covr::codecov()' \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index a249124..0cc15ed 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,10 +27,11 @@ Description: Cartogram heatmaps are an alternative to choropleth maps for 'USA' URL: https://github.com/hrbrmstr/statebins BugReports: https://github.com/hrbrmstr/statebins/issues License: MIT + file LICENSE -Suggests: +Suggests: testthat, viridis, - RColorBrewer + RColorBrewer, + covr Depends: R (>= 3.2.0), Imports: diff --git a/R/statebins.R b/R/statebins.R index 1e2fdee..5e31ecb 100644 --- a/R/statebins.R +++ b/R/statebins.R @@ -83,6 +83,7 @@ statebins <- function(state_data, gg <- gg + geom_text(data = st.dat, aes_string(x = "col", y = "row", label = "abbrev"), + angle = 0, color = .sb_invert(gb$data[[1]]$fill, dark_label, light_label), size = font_size) diff --git a/R/theme-statebin.R b/R/theme-statebin.R index 2edbc79..e12ca56 100644 --- a/R/theme-statebin.R +++ b/R/theme-statebin.R @@ -10,22 +10,23 @@ theme_statebins <- function(legend_position="bottom", base_size = 11, base_family = "") { - gg <- theme_bw(base_size = base_size, base_family = base_family) %+replace% - theme(axis.line = element_blank(), - axis.text = element_blank(), - axis.ticks = element_blank(), - axis.title = element_blank(), - panel.background = element_blank(), - panel.border = element_blank(), - panel.grid = element_blank(), - panel.spacing = unit(0, "lines"), - plot.background = element_blank(), - legend.justification = c(0, 0), - legend.position = legend_position) - + gg <- theme_bw(base_size = base_size, base_family = base_family) + gg <- gg + theme( + axis.line = element_blank(), + axis.text = element_blank(), + axis.ticks = element_blank(), + axis.title = element_blank(), + panel.background = element_blank(), + panel.border = element_blank(), + panel.grid = element_blank(), + panel.spacing = unit(0, "lines"), + plot.background = element_blank(), + legend.justification = c(0, 0), + legend.position = legend_position + ) gg <- gg + theme(strip.background = element_rect(color="#2b2b2b", fill="white")) - gg <- gg + theme(plot.title=element_text(hjust=0.5)) - gg <- gg + theme(axis.title.x=element_text(hjust=0.5)) + gg <- gg + theme(plot.title=element_text(hjust=0.5, angle=0)) + gg <- gg + theme(axis.title.x=element_text(hjust=0.5, angle=0)) gg <- gg + theme(legend.position=legend_position) gg <- gg + theme(plot.title=element_text(size=16, hjust=0)) gg <- gg + theme(plot.margin = margin(30,30,30,30)) diff --git a/README.Rmd b/README.Rmd index eafd77a..09d07c5 100644 --- a/README.Rmd +++ b/README.Rmd @@ -3,12 +3,19 @@ output: rmarkdown::github_document editor_options: chunk_output_type: console --- -```{r ugh, echo=FALSE, message=FALSE, warning=FALSE, error=FALSE, include=FALSE} -knitr::opts_chunk$set(message=FALSE, warning=FALSE, fig.retina=2) -options(width=120) -``` +[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) +[![Build Status](https://travis-ci.org/search/search.svg?branch=master)](https://travis-ci.org/search/search) +[![minimal R version](https://img.shields.io/badge/R%3E%3D-3.2.0-6666ff.svg)](https://cran.r-project.org/) +[![packageversion](https://img.shields.io/badge/Package%20version-2.0.0-orange.svg?style=flat-square)](commits/master) +![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/statebins) +[![](http://cranlogs.r-pkg.org/badges/statebins)](http://cran.rstudio.com/web/packages/statebins/index.html) [![Travis-CI Build Status](https://travis-ci.org/hrbrmstr/statebins.svg?branch=master)](https://travis-ci.org/hrbrmstr/statebins) +[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/hrbrmstr/statebins?branch=master&svg=true)](https://ci.appveyor.com/project/hrbrmstr/statebins) + +```{r include=FALSE} +knitr::opts_chunk$set(message=FALSE, warning=FALSE) +``` # statebins @@ -49,7 +56,7 @@ packageVersion("statebins") ### The original wapo data ```{r original} -adat <- suppressMessages(read_csv(system.file("extdata", "wapostates.csv", package="statebins"))) +adat <- read_csv(system.file("extdata", "wapostates.csv", package="statebins")) mutate( adat, @@ -68,11 +75,13 @@ mutate( ```{r continuous} statebins( - adat, value_col = "avgshare01_07", + adat, + value_col = "avgshare01_07", name = "Share of workforce with jobs lost or threatened by trade", - palette = "OrRd", direction = 1 + palette = "OrRd", + direction = 1 ) + - labs(x="2001-2007") + + labs(x="2001-2007") + theme_statebins(legend_position="top") ``` @@ -89,7 +98,7 @@ statebins(adat, value_col = "avgshare08_12", palette = "Purples") + ```{r mort} # from: http://www.cdc.gov/nchs/fastats/state-and-territorial-data.htm -dat <- suppressMessages(read_csv(system.file("extdata", "deaths.csv", package="statebins"))) +dat <- read_csv(system.file("extdata", "deaths.csv", package="statebins")) statebins(dat, value_col = "death_rate", name="Per 100K pop") + labs(title="Mortality Rate (2010)") + @@ -187,4 +196,4 @@ statebins(us_arrests, value_col="Assault", ggplot2_scale_function = viridis::scale_fill_viridis) + labs(title="USArrests + made up data") + theme_statebins("right") -``` \ No newline at end of file +``` diff --git a/README.md b/README.md index f78f207..10b674a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,18 @@ -[![Travis-CI Build Status](https://travis-ci.org/hrbrmstr/statebins.svg?branch=master)](https://travis-ci.org/hrbrmstr/statebins) + +[![Project Status: Active – The project has reached a stable, usable +state and is being actively +developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) +[![Build +Status](https://travis-ci.org/search/search.svg?branch=master)](https://travis-ci.org/search/search) +[![minimal R +version](https://img.shields.io/badge/R%3E%3D-3.2.0-6666ff.svg)](https://cran.r-project.org/) +[![packageversion](https://img.shields.io/badge/Package%20version-2.0.0-orange.svg?style=flat-square)](commits/master) +![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/statebins) +[![](http://cranlogs.r-pkg.org/badges/statebins)](http://cran.rstudio.com/web/packages/statebins/index.html) +[![Travis-CI Build +Status](https://travis-ci.org/hrbrmstr/statebins.svg?branch=master)](https://travis-ci.org/hrbrmstr/statebins) +[![AppVeyor Build +Status](https://ci.appveyor.com/api/projects/status/github/hrbrmstr/statebins?branch=master&svg=true)](https://ci.appveyor.com/project/hrbrmstr/statebins) # statebins @@ -49,7 +63,7 @@ packageVersion("statebins") ### The original wapo data ``` r -adat <- suppressMessages(read_csv(system.file("extdata", "wapostates.csv", package="statebins"))) +adat <- read_csv(system.file("extdata", "wapostates.csv", package="statebins")) mutate( adat, @@ -64,21 +78,23 @@ mutate( theme_statebins() ``` - +![](README_files/figure-gfm/original-1.png) ### Continuous scale, legend on top ``` r statebins( - adat, value_col = "avgshare01_07", + adat, + value_col = "avgshare01_07", name = "Share of workforce with jobs lost or threatened by trade", - palette = "OrRd", direction = 1 + palette = "OrRd", + direction = 1 ) + - labs(x="2001-2007") + + labs(x="2001-2007") + theme_statebins(legend_position="top") ``` - +![](README_files/figure-gfm/continuous-1.png) ### Continuous scale, no legend @@ -88,21 +104,21 @@ statebins(adat, value_col = "avgshare08_12", palette = "Purples") + theme_statebins(legend_position = "none") ``` - +![](README_files/figure-gfm/continuous_noleg-1.png) ### Mortality data (has Puerto Rico) ``` r # from: http://www.cdc.gov/nchs/fastats/state-and-territorial-data.htm -dat <- suppressMessages(read_csv(system.file("extdata", "deaths.csv", package="statebins"))) +dat <- read_csv(system.file("extdata", "deaths.csv", package="statebins")) statebins(dat, value_col = "death_rate", name="Per 100K pop") + labs(title="Mortality Rate (2010)") + theme_statebins() ``` - +![](README_files/figure-gfm/mort-1.png) ### Fertility data @@ -112,7 +128,7 @@ statebins(dat, value_col="fertility_rate", name="Per 100K pop", palette="PuBuGn" theme_statebins() ``` - +![](README_files/figure-gfm/fert-1.png) ### Manual - perhaps good for elections? @@ -129,7 +145,7 @@ mutate(election_2012, value = ifelse(is.na(Obama), "Romney", "Obama")) %>% theme_statebins() ``` - +![](README_files/figure-gfm/manual-1.png) ### Rounded rects\! @@ -145,7 +161,7 @@ statebins(USArrests, value_col="Assault", name = "Assault", round=TRUE) + theme_statebins(legend_position="right") ``` - +![](README_files/figure-gfm/rounded-1.png) Circles\! @@ -155,7 +171,7 @@ statebins(USArrests, value_col="Assault", name = "Assault", round=TRUE, theme_statebins(legend_position="right") ``` - +![](README_files/figure-gfm/rounded2-1.png) ### Geom @@ -175,7 +191,7 @@ ggplot(flu, aes(state=statename, fill=activity_level)) + theme(plot.margin = margin(30,30,30,30)) ``` - +![](README_files/figure-gfm/sb_facet-1.png) ### All the “states” @@ -208,4 +224,4 @@ statebins(us_arrests, value_col="Assault", theme_statebins("right") ``` - +![](README_files/figure-gfm/all-1.png) diff --git a/README_files/figure-gfm/all-1.png b/README_files/figure-gfm/all-1.png index f2e2fc5..1a046d2 100644 Binary files a/README_files/figure-gfm/all-1.png and b/README_files/figure-gfm/all-1.png differ diff --git a/README_files/figure-gfm/continuous-1.png b/README_files/figure-gfm/continuous-1.png index a0e305c..47e3e70 100644 Binary files a/README_files/figure-gfm/continuous-1.png and b/README_files/figure-gfm/continuous-1.png differ diff --git a/README_files/figure-gfm/continuous_noleg-1.png b/README_files/figure-gfm/continuous_noleg-1.png index a84bb68..8bd2dc3 100644 Binary files a/README_files/figure-gfm/continuous_noleg-1.png and b/README_files/figure-gfm/continuous_noleg-1.png differ diff --git a/README_files/figure-gfm/fert-1.png b/README_files/figure-gfm/fert-1.png index 5c76718..79f52a9 100644 Binary files a/README_files/figure-gfm/fert-1.png and b/README_files/figure-gfm/fert-1.png differ diff --git a/README_files/figure-gfm/manual-1.png b/README_files/figure-gfm/manual-1.png index 0daff8c..a3d21ca 100644 Binary files a/README_files/figure-gfm/manual-1.png and b/README_files/figure-gfm/manual-1.png differ diff --git a/README_files/figure-gfm/mort-1.png b/README_files/figure-gfm/mort-1.png index b3514eb..45795f7 100644 Binary files a/README_files/figure-gfm/mort-1.png and b/README_files/figure-gfm/mort-1.png differ diff --git a/README_files/figure-gfm/original-1.png b/README_files/figure-gfm/original-1.png index e382933..2db407c 100644 Binary files a/README_files/figure-gfm/original-1.png and b/README_files/figure-gfm/original-1.png differ diff --git a/README_files/figure-gfm/rounded-1.png b/README_files/figure-gfm/rounded-1.png index 405ef2d..e4ee524 100644 Binary files a/README_files/figure-gfm/rounded-1.png and b/README_files/figure-gfm/rounded-1.png differ diff --git a/README_files/figure-gfm/rounded2-1.png b/README_files/figure-gfm/rounded2-1.png index 69f01ed..9600390 100644 Binary files a/README_files/figure-gfm/rounded2-1.png and b/README_files/figure-gfm/rounded2-1.png differ diff --git a/README_files/figure-gfm/sb_facet-1.png b/README_files/figure-gfm/sb_facet-1.png index cea1416..be60bbf 100644 Binary files a/README_files/figure-gfm/sb_facet-1.png and b/README_files/figure-gfm/sb_facet-1.png differ diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..c6c1438 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,45 @@ +# DO NOT CHANGE the "init" and "install" sections below + +# Download script file from GitHub +init: + ps: | + $ErrorActionPreference = "Stop" + Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" + Import-Module '..\appveyor-tool.ps1' + +install: + ps: Bootstrap + +cache: + - C:\RLibrary + +# Adapt as necessary starting from here + +build_script: + - travis-tool.sh install_deps + +test_script: + - travis-tool.sh run_tests + +on_failure: + - 7z a failure.zip *.Rcheck\* + - appveyor PushArtifact failure.zip + +artifacts: + - path: '*.Rcheck\**\*.log' + name: Logs + + - path: '*.Rcheck\**\*.out' + name: Logs + + - path: '*.Rcheck\**\*.fail' + name: Logs + + - path: '*.Rcheck\**\*.Rout' + name: Logs + + - path: '\*_*.tar.gz' + name: Bits + + - path: '\*_*.zip' + name: Bits diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..8f36b6c --- /dev/null +++ b/codecov.yml @@ -0,0 +1,12 @@ +comment: false + +coverage: + status: + project: + default: + target: auto + threshold: 1% + patch: + default: + target: auto + threshold: 1%