Browse Source

statebins_manual

master
hrbrmstr 9 years ago
parent
commit
3cac431a37
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 11
      DESCRIPTION
  2. 22
      R/statebins.R
  3. 15
      README.Rmd
  4. 19
      README.md
  5. BIN
      README_files/figure-markdown_github/unnamed-chunk-31.png
  6. BIN
      README_files/figure-markdown_github/unnamed-chunk-32.png
  7. BIN
      README_files/figure-markdown_github/unnamed-chunk-33.png
  8. BIN
      README_files/figure-markdown_github/unnamed-chunk-34.png
  9. 7
      man/statebins_manual.Rd

11
DESCRIPTION

@ -1,8 +1,9 @@
Package: statebins
Type: Package
Title: statebins is an alternative to choropleth maps for USA States
Version: 1.0
Date: 2014-08-26
Title: statebins - U.S. State Cartogram Heatmaps in R; an alternative to
choropleth maps for USA States
Version: 1.1
Date: 2014-08-29
Author: Bob Rudis (@hrbrmstr)
Maintainer: Bob Rudis <bob@rudis.net>
Description: statebins is an alternative to choropleth maps for USA States and
@ -10,8 +11,8 @@ Description: statebins is an alternative to choropleth maps for USA States and
on "The states most threatened by trade". statebins preserves as much of
the geographic placement of the states as possible but has the look and
feel of a traditional heatmap. Functions are provided that allow for use
of both a binned, discrete scale and continuous scale depending on what
is needed for the underlying data.
of a binned, discrete scale, a continuous scale or manually specified
colors depending on what is needed for the underlying data.
URL: http://github.com/hrbrmstr/statebins
BugReports: https://github.com/hrbrmstr/statebins/issues
License: MIT + file LICENSE

22
R/statebins.R

@ -271,22 +271,12 @@ statebins_continuous <- function(state_data, state_col="state", value_col="value
#' @export
#' @examples
#' \dontrun{
#' election_2012 <- structure(list(state = c("AL", "AK", "AZ", "AR", "CA", "CO",
#' "CT", "DE", "DC", "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"), color = c("#2166ac", "#2166ac", "#2166ac", "#2166ac",
#' "#b2182b", "#b2182b", "#b2182b", "#b2182b", "#b2182b", "#b2182b",
#' "#2166ac", "#b2182b", "#2166ac", "#b2182b", "#2166ac", "#b2182b",
#' "#2166ac", "#2166ac", "#2166ac", "#b2182b", "#b2182b", "#b2182b",
#' "#b2182b", "#b2182b", "#2166ac", "#2166ac", "#2166ac", "#2166ac",
#' "#b2182b", "#b2182b", "#b2182b", "#b2182b", "#b2182b", "#2166ac",
#' "#2166ac", "#b2182b", "#2166ac", "#b2182b", "#b2182b", "#b2182b",
#' "#2166ac", "#2166ac", "#2166ac", "#2166ac", "#2166ac", "#b2182b",
#' "#b2182b", "#b2182b", "#2166ac", "#b2182b", "#2166ac")), class = "data.frame", row.names = c(NA,
#' -51L), .Names = c("state", "color"))
#' statebins_manual(election_2012, font_size=4, text_color = "white", labels=c("Romney", "Obama", "Hrm?"), legend_position="right", legend_title="Winner")
#' library(httr)
#' library(dplyr)
#' election_2012 <- GET("https://raw.githubusercontent.com/hrbrmstr/statebins/master/tmp/election2012.csv")
#' results <- read.csv(textConnection(content(election_2012, as="text")), header=TRUE, stringsAsFactors=FALSE)
#' results <- results %>% mutate(color=ifelse(is.na(Obama), "#2166ac", "#b2182b")) %>% select(state, color)
#' results %>% statebins_manual(font_size=4, text_color = "white", labels=c("Romney", "Obama"), legend_position="right", legend_title="Winner")
#' }
statebins_manual <- function(state_data, state_col="state", color_col="color",
text_color="black", font_size=3,

15
README.Rmd

@ -1,19 +1,20 @@
---
title: "README"
author: "Bob Rudis"
date: August 26, 2014
date: August 29, 2014
output:
md_document:
variant: markdown_github
---
<!-- output: html_document -->
statebins is an alternative to choropleth maps for USA States
statebins - U.S. State Cartogram Heatmaps in R; an alternative to choropleth maps for USA States
The following functions are implemented:
- `statebins` - creates "statebin" charts in the style of http://bit.ly/statebins - This version uses discrete `RColorBrewer` scales, binned by the "breaks" parameter.
- `statebins_continuous` - creates "statebin" charts in the style of http://bit.ly/statebins - This version uses a continuous scale based on `RColorBrewer` scales (passing in a 6 element `RColorBrewer` palette to `scale_fill_gradientn`).
- `statebins_manual` - creates "statebin" charts using manually specified colors in a column
### TODO
@ -22,6 +23,7 @@ The following functions are implemented:
### News
- Version `1.1.0` released - `statebins_manual()` for manual placement of colors and moving of AK in support of a [pull request](https://github.com/hrbrmstr/statebins/pull/1) by [hansthompson](https://github.com/hansthompson)
- Version `1.0.0` released
### Installation
@ -74,6 +76,15 @@ gg3 <- statebins_continuous(dat, "state", "avgshare08_12",
gg3
# manual - perhaps good for elections?
library(httr)
library(dplyr)
election_2012 <- GET("https://raw.githubusercontent.com/hrbrmstr/statebins/master/tmp/election2012.csv")
results <- read.csv(textConnection(content(election_2012, as="text")), header=TRUE, stringsAsFactors=FALSE)
results <- results %>% mutate(color=ifelse(is.na(Obama), "#2166ac", "#b2182b")) %>% select(state, color)
results %>% statebins_manual(font_size=4, text_color = "white", labels=c("Romney", "Obama"), legend_position="right", legend_title="Winner")
# or, more like the one in the WaPo article; i might be picking the wrong columns here. it's just for an example
sb <- function(col, title) {

19
README.md

@ -1,11 +1,12 @@
<!-- output: html_document -->
statebins is an alternative to choropleth maps for USA States
statebins - U.S. State Cartogram Heatmaps in R; an alternative to choropleth maps for USA States
The following functions are implemented:
- `statebins` - creates "statebin" charts in the style of <http://bit.ly/statebins> - This version uses discrete `RColorBrewer` scales, binned by the "breaks" parameter.
- `statebins_continuous` - creates "statebin" charts in the style of <http://bit.ly/statebins> - This version uses a continuous scale based on `RColorBrewer` scales (passing in a 6 element `RColorBrewer` palette to `scale_fill_gradientn`).
- `statebins_manual` - creates "statebin" charts using manually specified colors in a column
### TODO
@ -14,6 +15,7 @@ The following functions are implemented:
### News
- Version `1.1.0` released - `statebins_manual()` for manual placement of colors and moving of AK in support of a [pull request](https://github.com/hrbrmstr/statebins/pull/1) by [hansthompson](https://github.com/hansthompson)
- Version `1.0.0` released
### Installation
@ -78,6 +80,19 @@ gg3
![plot of chunk unnamed-chunk-3](./README_files/figure-markdown_github/unnamed-chunk-33.png)
``` {.r}
# manual - perhaps good for elections?
library(httr)
library(dplyr)
election_2012 <- GET("https://raw.githubusercontent.com/hrbrmstr/statebins/master/tmp/election2012.csv")
results <- read.csv(textConnection(content(election_2012, as="text")), header=TRUE, stringsAsFactors=FALSE)
results <- results %>% mutate(color=ifelse(is.na(Obama), "#2166ac", "#b2182b")) %>% select(state, color)
results %>% statebins_manual(font_size=4, text_color = "white", labels=c("Romney", "Obama"), legend_position="right", legend_title="Winner")
```
![plot of chunk unnamed-chunk-3](./README_files/figure-markdown_github/unnamed-chunk-34.png)
``` {.r}
# or, more like the one in the WaPo article; i might be picking the wrong columns here. it's just for an example
sb <- function(col, title) {
@ -175,7 +190,7 @@ library(testthat)
date()
```
## [1] "Tue Aug 26 17:53:56 2014"
## [1] "Fri Aug 29 12:38:53 2014"
``` {.r}
test_dir("tests/")

BIN
README_files/figure-markdown_github/unnamed-chunk-31.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

BIN
README_files/figure-markdown_github/unnamed-chunk-32.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

BIN
README_files/figure-markdown_github/unnamed-chunk-33.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

BIN
README_files/figure-markdown_github/unnamed-chunk-34.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

7
man/statebins_manual.Rd

@ -59,7 +59,12 @@ return a frame grob instead of a ggplot2 object.
}
\examples{
\dontrun{
statebins_manual(U)
library(httr)
library(dplyr)
election_2012 <- GET("https://raw.githubusercontent.com/hrbrmstr/statebins/master/tmp/election2012.csv")
results <- read.csv(textConnection(content(election_2012, as="text")), header=TRUE, stringsAsFactors=FALSE)
results <- results \%>\% mutate(color=ifelse(is.na(Obama), "#2166ac", "#b2182b")) \%>\% select(state, color)
results \%>\% statebins_manual(font_size=4, text_color = "white", labels=c("Romney", "Obama"), legend_position="right", legend_title="Winner")
}
}

Loading…
Cancel
Save