Browse Source

CRAN checks

master
Bob Rudis 10 years ago
parent
commit
a04399923e
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 1
      .Rbuildignore
  2. 3
      DESCRIPTION
  3. 1
      NAMESPACE
  4. 20
      R/state_coords.R
  5. 2
      R/statebins-package.R
  6. 62
      R/statebins.R
  7. 31
      README.md
  8. 22
      _README.Rmd
  9. 75
      _README.md
  10. BIN
      _README_files/figure-markdown_github/unnamed-chunk-31.png
  11. BIN
      _README_files/figure-markdown_github/unnamed-chunk-32.png
  12. BIN
      _README_files/figure-markdown_github/unnamed-chunk-33.png
  13. 25
      man/state_coords.Rd
  14. 41
      man/statebins.Rd
  15. 30
      man/statebins_continuous.Rd

1
.Rbuildignore

@ -1,6 +1,7 @@
^.*\.Rproj$
^\.Rproj\.user$
^_README.Rmd$
^_README.md$
^NEWS.md$
^\.travis\.yml$
^README.md$

3
DESCRIPTION

@ -17,4 +17,5 @@ Depends:
ggplot2,
grid,
scales,
gridExtra
gridExtra,
RColorBrewer

1
NAMESPACE

@ -2,6 +2,7 @@
export(statebins)
export(statebins_continuous)
import(RColorBrewer)
import(ggplot2)
import(grid)
import(gridExtra)

20
R/state_coords.R

@ -0,0 +1,20 @@
#' @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

2
R/statebins-package.R

@ -2,5 +2,5 @@
#' @name statebins
#' @docType package
#' @author Bob Rudis (@@hrbrmstr)
#' @import ggplot2 scales grid gridExtra
#' @import ggplot2 scales grid gridExtra RColorBrewer
NULL

62
R/statebins.R

@ -2,19 +2,20 @@
#' Create ggplot-based "statebin" charts in the style of \url{http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/}
#'
#' This version uses a discrete scale, binned by the "breaks" parameter
#' @param state_data
#' @param state_col
#' @param value_col
#' @param text_color
#' @param font_size
#' @param state_border_col
#' @param breaks
#' @param labels
#' @param legend_title
#' @param legend_position
#' @param brewer_pal
#' @param plot_title
#' @param title_position
#'
#' @param state_data data frame of states and values to plot
#' @param state_col column name in \code{state_data} that has the states. no duplicates and can be names (e.g. "Maine") or abbreviatons (e.g. "ME")
#' @param value_col column name in \code{state_data} that holds the values to be plotted
#' @param text_color default "white"
#' @param font_size font size (default = 2)
#' @param state_border_col default "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}
#' @param legend_title title for the legend
#' @param legend_position "none", "top" or "bottom" (defaults to "top")
#' @param brewer_pal which named RColorBrewer palette to use
#' @param plot_title title for the plot
#' @param title_position where to put the title ("bottom" or "top" or " " for none); if "bottom", you get back a grob vs a ggplot object
#' @return ggplot2 object or grob
#' @export
statebins <- function(state_data, state_col="state", value_col="value",
@ -40,9 +41,9 @@ statebins <- function(state_data, state_col="state", value_col="value",
st.dat$fill_color <- cut(st.dat[, value_col], breaks=breaks, labels=labels)
gg <- ggplot(st.dat, aes(x=col, y=row, label=abbrev))
gg <- gg + geom_tile(aes(fill=fill_color))
gg <- gg + geom_tile(color=state_border_col, aes(fill=fill_color), size=3, show_guide=FALSE)
gg <- ggplot(st.dat, aes_string(x="col", y="row", label="abbrev"))
gg <- gg + geom_tile(aes_string(fill="fill_color"))
gg <- gg + geom_tile(color=state_border_col, aes_string(fill="fill_color"), size=3, show_guide=FALSE)
gg <- gg + geom_text(color=text_color, size=font_size)
gg <- gg + scale_y_reverse()
gg <- gg + scale_fill_brewer(palette=brewer_pal, name=legend_title)
@ -76,18 +77,19 @@ statebins <- function(state_data, state_col="state", value_col="value",
#' Create ggplot-based "statebin" charts in the style of \url{http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/}
#'
#' This version uses a discrete scale, binned by the "breaks" parameter
#' @param state_data
#' @param state_col
#' @param value_col
#' @param text_color
#' @param font_size
#' @param state_border_col
#' @param legend_title
#' @param legend_position
#' @param brewer_pal
#' @param plot_title
#' @param title_position
#' This version uses a continuous scale akin to \link{scale_fill_distiller}
#'
#' @param state_data data frame of states and values to plot
#' @param state_col column name in \code{state_data} that has the states. no duplicates and can be names (e.g. "Maine") or abbreviatons (e.g. "ME")
#' @param value_col column name in \code{state_data} that holds the values to be plotted
#' @param text_color default "white"
#' @param font_size font size (default = 2)
#' @param state_border_col default "white" - this creates the "spaces" between boxes
#' @param legend_title title for the legend
#' @param legend_position "none", "top" or "bottom" (defaults to "top")
#' @param brewer_pal which named RColorBrewer palette to use
#' @param plot_title title for the plot
#' @param title_position where to put the title ("bottom" or "top" or " " for none); if "bottom", you get back a grob vs a ggplot object
#' @return ggplot2 object or grob
#' @export
statebins_continuous <- function(state_data, state_col="state", value_col="value",
@ -110,14 +112,14 @@ statebins_continuous <- function(state_data, state_col="state", value_col="value
st.dat <- merge(state_coords, state_data, by.x=merge.x, by.y=state_col)
gg <- ggplot(st.dat, aes(x=col, y=row, label=abbrev))
gg <- ggplot(st.dat, aes_string(x="col", y="row", label="abbrev"))
gg <- gg + geom_tile(aes_string(fill=value_col))
gg <- gg + geom_tile(color=state_border_col,
aes_string(fill=value_col), size=3, show_guide=FALSE)
gg <- gg + geom_text(color=text_color, size=font_size)
gg <- gg + scale_y_reverse()
gg <- gg + continuous_scale("fill", "distiller",
gradient_n_pal(brewer_pal(type, brewer_pal)(6), NULL, "Lab"), na.value = "grey50", name=legend_title)
gradient_n_pal(brewer_pal("seq", brewer_pal)(6), NULL, "Lab"), na.value = "grey50", name=legend_title)
gg <- gg + coord_equal()
gg <- gg + labs(x="", y="", title="")
gg <- gg + theme_bw()

31
README.md

@ -1,8 +1,9 @@
statesquares is ...
statebins is an alternative to choropleth maps for US States
The following functions are implemented:
- `statebins` -
- `statebins_continuous` -
### News
@ -18,14 +19,7 @@ devtools::install_github("hrbrmstr/statebins")
``` {.r}
library(statebins)
```
## Loading required package: ggplot2
## Loading required package: grid
## Loading required package: scales
## Loading required package: gridExtra
``` {.r}
# current verison
packageVersion("statebins")
```
@ -33,11 +27,13 @@ packageVersion("statebins")
## [1] '1.0'
``` {.r}
# the original wapo data
dat <- read.csv("http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/states.csv?cache=1", stringsAsFactors=FALSE)
gg <- statebins(dat, "state", "avgshare94_00", breaks=4,
labels=c("0-1", "1-2", "2-3", "3-4"),
legend_title="State Groups",
legend_title="State Groups", font_size=3,
brewer_pal="Blues", text_color="black",
plot_title="1994-2000", title_position="bottom")
@ -49,14 +45,25 @@ gg
``` {.r}
gg2 <- statebins_continuous(dat, "state", "avgshare01_07",
legend_title="States", legend_position="none",
brewer_pal="OrRd", text_color="black",
plot_title="1994-2000", title_position="bottom")
brewer_pal="OrRd", text_color="black", font_size=3,
plot_title="2001-2007", title_position="bottom")
gg2
```
![plot of chunk unnamed-chunk-3](./_README_files/figure-markdown_github/unnamed-chunk-32.png)
``` {.r}
gg3 <- statebins_continuous(dat, "state", "avgshare08_12",
legend_title="States", legend_position="none",
brewer_pal="Purples", text_color="black", font_size=3,
plot_title="2008-2012", title_position="bottom")
gg3
```
![plot of chunk unnamed-chunk-3](./_README_files/figure-markdown_github/unnamed-chunk-33.png)
### Test Results
``` {.r}
@ -66,7 +73,7 @@ library(testthat)
date()
```
## [1] "Mon Aug 25 22:25:49 2014"
## [1] "Mon Aug 25 22:36:21 2014"
``` {.r}
test_dir("tests/")

22
_README.Rmd

@ -7,15 +7,16 @@ output:
variant: markdown_github
---
statesquares is ...
statebins is an alternative to choropleth maps for US States
The following functions are implemented:
- `statebins` -
- `statebins_continuous` -
### News
- Version `1.0.0` released
- Version `1.0.0` released
### Installation
@ -29,17 +30,19 @@ options(width=120)
### Usage
```{r}
```{r message=FALSE}
library(statebins)
# current verison
packageVersion("statebins")
# the original wapo data
dat <- read.csv("http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/states.csv?cache=1", stringsAsFactors=FALSE)
gg <- statebins(dat, "state", "avgshare94_00", breaks=4,
labels=c("0-1", "1-2", "2-3", "3-4"),
legend_title="State Groups",
legend_title="State Groups", font_size=3,
brewer_pal="Blues", text_color="black",
plot_title="1994-2000", title_position="bottom")
@ -47,11 +50,18 @@ gg
gg2 <- statebins_continuous(dat, "state", "avgshare01_07",
legend_title="States", legend_position="none",
brewer_pal="OrRd", text_color="black",
plot_title="1994-2000", title_position="bottom")
brewer_pal="OrRd", text_color="black", font_size=3,
plot_title="2001-2007", title_position="bottom")
gg2
gg3 <- statebins_continuous(dat, "state", "avgshare08_12",
legend_title="States", legend_position="none",
brewer_pal="Purples", text_color="black", font_size=3,
plot_title="2008-2012", title_position="bottom")
gg3
```
### Test Results

75
_README.md

@ -1,75 +0,0 @@
statesquares is ...
The following functions are implemented:
- `statebins` -
### News
- Version `1.0.0` released
### Installation
``` {.r}
devtools::install_github("hrbrmstr/statebins")
```
### Usage
``` {.r}
library(statebins)
```
## Loading required package: ggplot2
## Loading required package: grid
## Loading required package: scales
## Loading required package: gridExtra
``` {.r}
# current verison
packageVersion("statebins")
```
## [1] '1.0'
``` {.r}
dat <- read.csv("http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/states.csv?cache=1", stringsAsFactors=FALSE)
gg <- statebins(dat, "state", "avgshare94_00", breaks=4,
labels=c("0-1", "1-2", "2-3", "3-4"),
legend_title="State Groups",
brewer_pal="Blues", text_color="black",
plot_title="1994-2000", title_position="bottom")
gg
```
![plot of chunk unnamed-chunk-3](./_README_files/figure-markdown_github/unnamed-chunk-31.png)
``` {.r}
gg2 <- statebins_continuous(dat, "state", "avgshare01_07",
legend_title="States", legend_position="none",
brewer_pal="OrRd", text_color="black",
plot_title="1994-2000", title_position="bottom")
gg2
```
![plot of chunk unnamed-chunk-3](./_README_files/figure-markdown_github/unnamed-chunk-32.png)
### Test Results
``` {.r}
library(statebins)
library(testthat)
date()
```
## [1] "Mon Aug 25 22:27:38 2014"
``` {.r}
test_dir("tests/")
```
## basic functionality :

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 32 KiB

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 30 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

25
man/state_coords.Rd

@ -0,0 +1,25 @@
% Generated by roxygen2 (4.0.1.99): 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}

41
man/statebins.Rd

@ -3,15 +3,46 @@
\name{statebins}
\alias{statebins}
\alias{statebins-package}
\title{A package to ...}
\title{statebins is an alternative to choropleth maps for US States}
\usage{
statebins(state_data, state_col = "state", value_col = "value",
text_color = "white", state_border_col = "white", breaks = 5,
labels = 1:4, legend_title = "Legend", legend_position = "top",
brewer_pal = "PuBu", plot_title = "", title_position = "bottom")
text_color = "white", font_size = 2, state_border_col = "white",
breaks = 5, labels = 1:4, legend_title = "Legend",
legend_position = "top", brewer_pal = "PuBu", plot_title = "",
title_position = "bottom")
}
\arguments{
\item{state_data}{data frame of states and values to plot}
\item{state_col}{column name in \code{state_data} that has the states. no duplicates and can be names (e.g. "Maine") or abbreviatons (e.g. "ME")}
\item{value_col}{column name in \code{state_data} that holds the values to be plotted}
\item{text_color}{default "white"}
\item{font_size}{font size (default = 2)}
\item{state_border_col}{default "white" - this creates the "spaces" between boxes}
\item{breaks}{a single number (greater than or equal to 2) giving the number of intervals into which data values are to be cut.}
\item{labels}{labels for the levels \code{breaks}}
\item{legend_title}{title for the legend}
\item{legend_position}{"none", "top" or "bottom" (defaults to "top")}
\item{brewer_pal}{which named RColorBrewer palette to use}
\item{plot_title}{title for the plot}
\item{title_position}{where to put the title ("bottom" or "top" or " " for none); if "bottom", you get back a grob vs a ggplot object}
}
\value{
ggplot2 object or grob
}
\description{
A package to ...
statebins is an alternative to choropleth maps for US States
This version uses a discrete scale, binned by the "breaks" parameter
}

30
man/statebins_continuous.Rd

@ -4,11 +4,37 @@
\title{Create ggplot-based "statebin" charts in the style of \url{http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/}}
\usage{
statebins_continuous(state_data, state_col = "state", value_col = "value",
text_color = "white", state_border_col = "white",
text_color = "white", font_size = 2, state_border_col = "white",
legend_title = "Legend", legend_position = "top", brewer_pal = "PuBu",
plot_title = "", title_position = "bottom")
}
\arguments{
\item{state_data}{data frame of states and values to plot}
\item{state_col}{column name in \code{state_data} that has the states. no duplicates and can be names (e.g. "Maine") or abbreviatons (e.g. "ME")}
\item{value_col}{column name in \code{state_data} that holds the values to be plotted}
\item{text_color}{default "white"}
\item{font_size}{font size (default = 2)}
\item{state_border_col}{default "white" - this creates the "spaces" between boxes}
\item{legend_title}{title for the legend}
\item{legend_position}{"none", "top" or "bottom" (defaults to "top")}
\item{brewer_pal}{which named RColorBrewer palette to use}
\item{plot_title}{title for the plot}
\item{title_position}{where to put the title ("bottom" or "top" or " " for none); if "bottom", you get back a grob vs a ggplot object}
}
\value{
ggplot2 object or grob
}
\description{
This version uses a discrete scale, binned by the "breaks" parameter
This version uses a continuous scale akin to \link{scale_fill_distiller}
}

Loading…
Cancel
Save