Browse Source

Updating for CRAN submission

master
hrbrmstr 10 years ago
parent
commit
7b07e967a7
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 7
      DESCRIPTION
  2. 20
      R/state_coords.R
  3. 60
      R/statebins.R
  4. 4
      README.Rmd
  5. 4
      README.md
  6. BIN
      README_files/figure-markdown_github/unnamed-chunk-31.png
  7. BIN
      README_files/figure-markdown_github/unnamed-chunk-32.png
  8. BIN
      README_files/figure-markdown_github/unnamed-chunk-33.png
  9. BIN
      _README_files/figure-markdown_github/unnamed-chunk-31.png
  10. BIN
      _README_files/figure-markdown_github/unnamed-chunk-32.png
  11. BIN
      _README_files/figure-markdown_github/unnamed-chunk-33.png
  12. BIN
      data/states.rda
  13. 25
      man/state_coords.Rd
  14. 16
      man/statebins.Rd
  15. 16
      man/statebins_continuous.Rd

7
DESCRIPTION

@ -1,21 +1,20 @@
Package: statebins
Type: Package
Title: statebins is an alternative to choropleth maps for US States
Title: statebins is an alternative to choropleth maps for USA States
Version: 1.0
Date: 2014-08-26
Author: Bob Rudis (@hrbrmstr)
Maintainer: Bob Rudis <bob@rudis.net>
Description: statebins is an alternative to choropleth maps for US States and
Description: statebins is an alternative to choropleth maps for USA States and
is based on work by the Washington Post graphics department in their report
on "The states most threatened by trade". statebins preserves as much of
the geographic placment of the states as possible but has the look and
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.
URL: http://github.com/hrbrmstr/statebins
BugReports: https://github.com/hrbrmstr/statebins/issues
License: MIT + file LICENSE
LazyData: yes
Suggests:
testthat
Depends:

20
R/state_coords.R

@ -1,20 +0,0 @@
#' @title state_coords
#' @description simple coordinates for states to use in a 'statebin' plot
#' \itemize{
#' \item \code{abbrev}. state abbreviation, including \code{DC} (chr)
#' \item \code{state}. capitalized state name (chr)
#' \item \code{col}. colum where it fits (12x8 grid) (chr)
#' \item \code{row}. row where it fits (12x8 grid) (chr)
#' }
#'
#' @docType data
#' @keywords datasets
#' @name state_coords
#' @seealso \itemize{
#' \item WaPo - \url{http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/}
#' }
#' @note Last updated 2014-08-25
#' @format A data frame with 51 rows and 4 variables
NULL

60
R/statebins.R

@ -1,3 +1,29 @@
state_coords <- 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"),
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"),
col = c(8L, 2L, 3L, 6L, 2L, 4L, 11L, 10L, 11L, 10L,
9L, 1L, 3L, 7L, 7L, 6L, 5L, 7L, 6L, 12L, 10L, 11L, 8L, 6L, 7L,
6L, 4L, 5L, 3L, 12L, 10L, 4L, 10L, 8L, 5L, 8L, 5L, 2L, 9L, 12L,
9L, 5L, 7L, 5L, 3L, 11L, 9L, 2L, 8L, 7L, 4L),
row = c(7L, 8L,
6L, 6L, 5L, 5L, 4L, 6L, 5L, 8L, 7L, 8L, 3L, 3L, 4L, 4L, 6L, 5L,
7L, 1L, 5L, 3L, 3L, 3L, 7L, 5L, 3L, 5L, 4L, 2L, 4L, 6L, 3L, 6L,
3L, 4L, 7L, 4L, 4L, 4L, 6L, 4L, 6L, 8L, 5L, 2L, 5L, 3L, 5L, 2L, 4L)),
.Names = c("abbrev", "state", "col", "row"), class = "data.frame", row.names = c(NA, -51L))
invert <- function(hexColor, darkColor="black", lightColor="white") {
hexColor <- gsub("#", "", hexColor)
@ -18,7 +44,7 @@ invert <- function(hexColor, darkColor="black", lightColor="white") {
}
#' Create a new ggplot-based "statebin" chart
#' Create a new ggplot-based "statebin" chart for USA states (discrete scale)
#'
#' \code{statebins()} creates "statebin" charts in the style of \url{http://bit.ly/statebins}
#'
@ -37,7 +63,7 @@ invert <- function(hexColor, darkColor="black", lightColor="white") {
#' and \code{value_col} accordingly.
#'
#' To add a title, change \code{plot_title} to anything but an empty atomic string vector (i.e. \code{""})
#' and set \code{title_positioin} to "\code{top}" or "\code{bottom}". Choosing "\code{bottom}"
#' and set \code{title_position} to "\code{top}" or "\code{bottom}". Choosing "\code{bottom}"
#' will cause \code{statebins} to use \link{arrangeGrob} to position the title via \code{sub} and
#' return a frame grob instead of a ggplot2 object.
#'
@ -45,7 +71,7 @@ invert <- function(hexColor, darkColor="black", lightColor="white") {
#' @param state_col column name in \code{state_data} that has the states. no duplicates and can be names (e.g. "\code{Maine}") or abbreviatons (e.g. "\code{ME}")
#' @param value_col column name in \code{state_data} that holds the values to be plotted
#' @param text_color default "\code{white}"
#' @param font_size font size (default = \code{2})
#' @param font_size font size (default = \code{3})
#' @param state_border_col default "\code{white}" - this creates the "spaces" between boxes
#' @param breaks a single number (greater than or equal to 2) giving the number of intervals into which data values are to be cut.
#' @param labels labels for the levels \code{breaks}
@ -56,8 +82,15 @@ invert <- function(hexColor, darkColor="black", lightColor="white") {
#' @param title_position where to put the title ("\code{bottom}" or "\code{top}" or "" for none); if "\code{bottom}", you get back a grob vs a ggplot object
#' @return ggplot2 object or grob
#' @export
#' @examples
#' \dontrun{
#' data(USArrests)
#' USArrests$state <- rownames(USArrests)
#' statebins(USArrests, value_col="Assault", text_color="black", font_size=3,
#' legend_title = "Assault", legend_position="bottom")
#' }
statebins <- function(state_data, state_col="state", value_col="value",
text_color="white", font_size=2,
text_color="white", font_size=3,
state_border_col="white", breaks=5, labels=1:5,
legend_title="Legend", legend_position="top",
brewer_pal="PuBu", plot_title="", title_position="bottom") {
@ -88,8 +121,6 @@ statebins <- function(state_data, state_col="state", value_col="value",
gg <- gg + coord_equal()
gg <- gg + labs(x=NULL, y=NULL, title=NULL)
gg <- gg + theme_bw()
gg <- gg + theme(plot.margin=unit(c(-1, 0, 0, 0), "line"))
gg <- gg + theme(panel.margin=unit(-1, "line"))
gg <- gg + theme(legend.position=legend_position)
gg <- gg + theme(panel.border=element_blank())
gg <- gg + theme(panel.grid=element_blank())
@ -112,7 +143,7 @@ statebins <- function(state_data, state_col="state", value_col="value",
}
#' Create ggplot-based "statebin" charts in the style of \url{http://bit.ly/statebins}
#' Create a new ggplot-based "statebin" chart for USA states (continuous scale)
#'
#' \code{statebins()} creates "statebin" charts in the style of \url{http://bit.ly/statebins}
#'
@ -132,7 +163,7 @@ statebins <- function(state_data, state_col="state", value_col="value",
#' and \code{value_col} accordingly.
#'
#' To add a title, change \code{plot_title} to anything but an empty atomic string vector (i.e. \code{""})
#' and set \code{title_positioin} to "\code{top}" or "\code{bottom}". Choosing "\code{bottom}"
#' and set \code{title_position} to "\code{top}" or "\code{bottom}". Choosing "\code{bottom}"
#' will cause \code{statebins} to use \link{arrangeGrob} to position the title via \code{sub} and
#' return a frame grob instead of a ggplot2 object.
#'
@ -140,7 +171,7 @@ statebins <- function(state_data, state_col="state", value_col="value",
#' @param state_col column name in \code{state_data} that has the states. no duplicates and can be names (e.g. "\code{Maine}") or abbreviatons (e.g. "\code{ME}")
#' @param value_col column name in \code{state_data} that holds the values to be plotted
#' @param text_color default "\code{white}"
#' @param font_size font size (default = \code{2})
#' @param font_size font size (default = \code{3})
#' @param state_border_col default "\code{white}" - this creates the "spaces" between boxes
#' @param legend_title title for the legend
#' @param legend_position "\code{none}", "\code{top}", "\code{left}", "\code{right}" or "\code{bottom}" (defaults to "\code{top}")
@ -149,8 +180,15 @@ statebins <- function(state_data, state_col="state", value_col="value",
#' @param title_position where to put the title ("\code{bottom}" or "\code{top}" or "" for none); if "\code{bottom}", you get back a grob vs a ggplot object
#' @return ggplot2 object or grob
#' @export
#' @examples
#' \dontrun{
#' data(USArrests)
#' USArrests$state <- rownames(USArrests)
#' statebins_continuous(USArrests, value_col="Murder", text_color="black", font_size=3,
#' legend_title = "Murder", legend_position="bottom")
#' }
statebins_continuous <- function(state_data, state_col="state", value_col="value",
text_color="white", font_size=2,
text_color="white", font_size=3,
state_border_col="white",
legend_title="Legend", legend_position="top",
brewer_pal="PuBu", plot_title="", title_position="bottom") {
@ -179,8 +217,6 @@ statebins_continuous <- function(state_data, state_col="state", value_col="value
gg <- gg + coord_equal()
gg <- gg + labs(x=NULL, y=NULL, title=NULL)
gg <- gg + theme_bw()
gg <- gg + theme(plot.margin=unit(c(-1, 0, 0, 0), "line"))
gg <- gg + theme(panel.margin=unit(-1, "line"))
gg <- gg + theme(legend.position=legend_position)
gg <- gg + theme(panel.border=element_blank())
gg <- gg + theme(panel.grid=element_blank())

4
_README.Rmd → README.Rmd

@ -8,7 +8,7 @@ output:
---
<!-- output: html_document -->
statebins is an alternative to choropleth maps for US States
statebins is an alternative to choropleth maps for USA States
The following functions are implemented:
@ -36,7 +36,7 @@ options(width=120)
### Usage
All of the following examples use the [WaPo data](http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/states.csv?cache=1). It looks like the colums they use are scaled data and I didn't take the time to figure out what they did, so the final figure just mimics their output (including the non-annotated legend).
All of the following examples use the [WaPo data](http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/states.csv?cache=1). It looks like the columns they use are scaled data and I didn't take the time to figure out what they did, so the final figure just mimics their output (including the non-annotated legend).
```{r message=FALSE}
library(statebins)

4
README.md

@ -128,9 +128,7 @@ sb("avgshare08_12", "2008-2012")
-->
<center>
![img](./tmp/statebins-composite.png)
</center>
And, we'll throw in a gratuitous animation for good measure:
@ -177,7 +175,7 @@ library(testthat)
date()
```
## [1] "Tue Aug 26 15:38:13 2014"
## [1] "Tue Aug 26 17:39:41 2014"
``` {.r}
test_dir("tests/")

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

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
data/states.rda

Binary file not shown.

25
man/state_coords.Rd

@ -1,25 +0,0 @@
% Generated by roxygen2 (4.0.1): do not edit by hand
\docType{data}
\name{state_coords}
\alias{state_coords}
\title{state_coords}
\format{A data frame with 51 rows and 4 variables}
\description{
simple coordinates for states to use in a 'statebin' plot
\itemize{
\item \code{abbrev}. state abbreviation, including \code{DC} (chr)
\item \code{state}. capitalized state name (chr)
\item \code{col}. colum where it fits (12x8 grid) (chr)
\item \code{row}. row where it fits (12x8 grid) (chr)
}
}
\note{
Last updated 2014-08-25
}
\seealso{
\itemize{
\item WaPo - \url{http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/}
}
}
\keyword{datasets}

16
man/statebins.Rd

@ -1,10 +1,10 @@
% Generated by roxygen2 (4.0.1): do not edit by hand
\name{statebins}
\alias{statebins}
\title{Create a new ggplot-based "statebin" chart}
\title{Create a new ggplot-based "statebin" chart for USA states (discrete scale)}
\usage{
statebins(state_data, state_col = "state", value_col = "value",
text_color = "white", font_size = 2, state_border_col = "white",
text_color = "white", font_size = 3, state_border_col = "white",
breaks = 5, labels = 1:5, legend_title = "Legend",
legend_position = "top", brewer_pal = "PuBu", plot_title = "",
title_position = "bottom")
@ -18,7 +18,7 @@ statebins(state_data, state_col = "state", value_col = "value",
\item{text_color}{default "\code{white}"}
\item{font_size}{font size (default = \code{2})}
\item{font_size}{font size (default = \code{3})}
\item{state_border_col}{default "\code{white}" - this creates the "spaces" between boxes}
@ -58,8 +58,16 @@ You can use a different column for the state names and values by changing \code{
and \code{value_col} accordingly.
To add a title, change \code{plot_title} to anything but an empty atomic string vector (i.e. \code{""})
and set \code{title_positioin} to "\code{top}" or "\code{bottom}". Choosing "\code{bottom}"
and set \code{title_position} to "\code{top}" or "\code{bottom}". Choosing "\code{bottom}"
will cause \code{statebins} to use \link{arrangeGrob} to position the title via \code{sub} and
return a frame grob instead of a ggplot2 object.
}
\examples{
\dontrun{
data(USArrests)
USArrests$state <- rownames(USArrests)
statebins(USArrests, value_col="Assault", text_color="black", font_size=3,
legend_title = "Assault", legend_position="bottom")
}
}

16
man/statebins_continuous.Rd

@ -1,10 +1,10 @@
% Generated by roxygen2 (4.0.1): do not edit by hand
\name{statebins_continuous}
\alias{statebins_continuous}
\title{Create ggplot-based "statebin" charts in the style of \url{http://bit.ly/statebins}}
\title{Create a new ggplot-based "statebin" chart for USA states (continuous scale)}
\usage{
statebins_continuous(state_data, state_col = "state", value_col = "value",
text_color = "white", font_size = 2, state_border_col = "white",
text_color = "white", font_size = 3, state_border_col = "white",
legend_title = "Legend", legend_position = "top", brewer_pal = "PuBu",
plot_title = "", title_position = "bottom")
}
@ -17,7 +17,7 @@ statebins_continuous(state_data, state_col = "state", value_col = "value",
\item{text_color}{default "\code{white}"}
\item{font_size}{font size (default = \code{2})}
\item{font_size}{font size (default = \code{3})}
\item{state_border_col}{default "\code{white}" - this creates the "spaces" between boxes}
@ -54,8 +54,16 @@ You can use a different column for the state names and values by changing \code{
and \code{value_col} accordingly.
To add a title, change \code{plot_title} to anything but an empty atomic string vector (i.e. \code{""})
and set \code{title_positioin} to "\code{top}" or "\code{bottom}". Choosing "\code{bottom}"
and set \code{title_position} to "\code{top}" or "\code{bottom}". Choosing "\code{bottom}"
will cause \code{statebins} to use \link{arrangeGrob} to position the title via \code{sub} and
return a frame grob instead of a ggplot2 object.
}
\examples{
\dontrun{
data(USArrests)
USArrests$state <- rownames(USArrests)
statebins_continuous(USArrests, value_col="Murder", text_color="black", font_size=3,
legend_title = "Murder", legend_position="bottom")
}
}

Loading…
Cancel
Save