#' \code{statebins()} creates "statebin" charts in the style of \url{http://bit.ly/statebins}
#' \code{statebins()} creates "statebin" charts in the style of \url{http://bit.ly/statebins}
#'
#'
#' This version uses discrete \link{RColorBrewer} scales, binned by the "breaks" parameter.
#' This version uses discrete \code{RColorBrewer} scales, binned by the "breaks" parameter.
#'
#'
#' The function minimally expects the caller to pass in a data frame that:
#' The function minimally expects the caller to pass in a data frame that:
#'
#'
#' \itemize{
#' \itemize{
#' \item has one column of all state abbreviationis (all caps, including \code{DC} & \code{PR} or a column of state names (standard capitalization) named \code{state}
#' \item has one column of all state abbreviationis (all caps, including \code{DC} &
#' \code{PR} or a column of state names (standard capitalization) named \code{state}
#' \item has another column of values named \code{value}
#' \item has another column of values named \code{value}
#' }
#' }
#'
#'
#' Doing so will create a "statebin" chart with 5 breaks and return a \link{ggplot2} object.
#' Doing so will create a "statebin" chart with 5 breaks and return a ggplot2 object.
#'
#'
#' You can use a different column for the state names and values by changing \code{state_col}
#' You can use a different column for the state names and values by changing \code{state_col}
#' and \code{value_col} accordingly.
#' and \code{value_col} accordingly.
#'
#'
#' To add a title, change \code{plot_title} to anything but an empty atomic string vector (i.e. \code{""})
#' To add a title, change \code{plot_title} to anything but an empty atomic string vector (i.e. \code{""})
#' and set \code{title_position} 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
#' will cause \code{statebins} to use \code{arrangeGrob} to position the title via \code{sub} and
#' return a frame grob instead of a ggplot2 object.
#' return a frame grob instead of a ggplot2 object.
#'
#'
#' @param state_data data frame of states and values to plot
#' @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. "\code{Maine}") or abbreviatons (e.g. "\code{ME}")
#' @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 value_col column name in \code{state_data} that holds the values to be plotted
#' @param text_color default "\code{black}"
#' @param text_color default "\code{black}"
#' @param font_size font size (default = \code{3})
#' @param font_size font size (default = \code{3})
#' @param state_border_col default "\code{white}" - this creates the "spaces" between boxes
#' @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 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 labels labels for the levels \code{breaks}
#' @param legend_title title for the legend
#' @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}")
#' @param legend_position "\code{none}", "\code{top}", "\code{left}", "\code{right}" or
#' @param brewer_pal which named \link{RColorBrewer} palette to use (defaults to "PuBu")
#' "\code{bottom}" (defaults to "\code{top}")
#' @param brewer_pal which named \code{RColorBrewer} palette to use (defaults to "PuBu")
#' @param plot_title title for the plot
#' @param plot_title title for the plot
#' @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
#' @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
#' \code{statebins()} creates "statebin" charts in the style of \url{http://bit.ly/statebins}
#' \code{statebins()} creates "statebin" charts in the style of \url{http://bit.ly/statebins}
#'
#'
#' This version uses a continuous scale based on \link{RColorBrewer} scales
#' This version uses a continuous scale based on \code{RColorBrewer} scales
#' (passing in a 6 element \code{RColorBrewer} palette to \link{scale_fill_gradientn}).
#' (passing in a 6 element \code{RColorBrewer} palette to \code{scale_fill_gradientn}).
#'
#'
#' The function minimally expects the caller to pass in a data frame that:
#' The function minimally expects the caller to pass in a data frame that:
#'
#'
#' \itemize{
#' \itemize{
#' \item has one column of all state abbreviationis (all caps, including \code{DC} & \code{PR} ) or a column of state names (standard capitalization) named \code{state}
#' \item has one column of all state abbreviationis (all caps, including \code{DC} &
#' \code{PR} ) or a column of state names (standard capitalization) named \code{state}
#' \item has another column of values named \code{value}
#' \item has another column of values named \code{value}
#' }
#' }
#'
#'
#' Doing so will create a "statebin" chart with 5 breaks and return a \link{ggplot2} object.
#' Doing so will create a "statebin" chart with 5 breaks and return a \code{ggplot2} object.
#'
#'
#' You can use a different column for the state names and values by changing \code{state_col}
#' You can use a different column for the state names and values by changing \code{state_col}
#' and \code{value_col} accordingly.
#' and \code{value_col} accordingly.
#'
#'
#' To add a title, change \code{plot_title} to anything but an empty atomic string vector (i.e. \code{""})
#' To add a title, change \code{plot_title} to anything but an empty atomic string vector (i.e. \code{""})
#' and set \code{title_position} 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
#' will cause \code{statebins} to use \code{arrangeGrob} to position the title via \code{sub} and
#' return a frame grob instead of a ggplot2 object.
#' return a frame grob instead of a ggplot2 object.
#'
#'
#' @param state_data data frame of states and values to plot
#' @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. "\code{Maine}") or abbreviatons (e.g. "\code{ME}")
#' @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 value_col column name in \code{state_data} that holds the values to be plotted
#' @param text_color default "\code{black}"
#' @param text_color default "\code{black}"
#' @param font_size font size (default = \code{3})
#' @param font_size font size (default = \code{3})
#' @param state_border_col default "\code{white}" - this creates the "spaces" between boxes
#' @param state_border_col default "\code{white}" - this creates the "spaces" between boxes
#' @param legend_title title for the legend
#' @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}")
#' @param legend_position "\code{none}", "\code{top}", "\code{left}", "\code{right}" or
#' @param brewer_pal which named \link{RColorBrewer} palette to use (defaults to "PuBu")
#' "\code{bottom}" (defaults to "\code{top}")
#' @param brewer_pal which named \code{RColorBrewer} palette to use (defaults to "PuBu")
#' @param plot_title title for the plot
#' @param plot_title title for the plot
#' @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
#' @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
#' The function minimally expects the caller to pass in a data frame that:
#' The function minimally expects the caller to pass in a data frame that:
#'
#'
#' \itemize{
#' \itemize{
#' \item has one column of all state abbreviationis (all caps, including \code{DC} & \code{PR} or a column of state names (standard capitalization) named \code{state}
#' \item has one column of all state abbreviationis (all caps, including \code{DC} &
#' \code{PR} or a column of state names (standard capitalization) named \code{state}
#' \item has another column of colors named \code{color}
#' \item has another column of colors named \code{color}
#' }
#' }
#'
#'
#' Doing so will create a "statebin" chart with the colors specified as a \link{ggplot2} object.
#' Doing so will create a "statebin" chart with the colors specified as a ggplot2 object.
#'
#'
#' You can use a different column for the state names and colors by changing \code{state_col}
#' You can use a different column for the state names and colors by changing \code{state_col}
#' and \code{color_col} accordingly.
#' and \code{color_col} accordingly.
#'
#'
#' To add a title, change \code{plot_title} to anything but an empty atomic string vector (i.e. \code{""})
#' To add a title, change \code{plot_title} to anything but an empty atomic string vector (i.e. \code{""})
#' and set \code{title_position} 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
#' will cause \code{statebins} to use \code{arrangeGrob} to position the title via \code{sub} and
#' return a frame grob instead of a ggplot2 object.
#' return a frame grob instead of a ggplot2 object.
#'
#'
#' @param state_data data frame of states and values to plot
#' @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. "\code{Maine}") or abbreviatons (e.g. "\code{ME}")
#' @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 color_col column name in \code{state_data} that holds the colors to be used
#' @param color_col column name in \code{state_data} that holds the colors to be used
#' @param text_color default "\code{black}"
#' @param text_color default "\code{black}"
#' @param font_size font size (default = \code{3})
#' @param font_size font size (default = \code{3})
#' @param state_border_col default "\code{white}" - this creates the "spaces" between boxes
#' @param state_border_col default "\code{white}" - this creates the "spaces" between boxes
#' @param labels labels for the legend (should be the same number as distinct colors in \code{color_col}); \code{NULL} == no labels/legend
#' @param labels labels for the legend (should be the same number as distinct colors in
#' \code{color_col}); \code{NULL} == no labels/legend
#' @param legend_title title for the legend
#' @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}")
#' @param legend_position "\code{none}", "\code{top}", "\code{left}", "\code{right}" or
#' "\code{bottom}" (defaults to "\code{top}")
#' @param plot_title title for the plot
#' @param plot_title title for the plot
#' @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
#' @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
@ -23,6 +23,7 @@ The following functions are implemented:
### News
### News
- Version `1.2.2` released (CRAN update)
- Version `1.2.1` released - Added support for `PR`/`Puerto Rico`[[1](https://github.com/hrbrmstr/statebins/issues/2)] and fixed a bug[[2](https://github.com/hrbrmstr/statebins/issues/3)] when using anything but a `data.frame` as input. Also no longer fails (deals with the following but with a warning) when duplicate states are in the input data or invalid states are in the input data.
- Version `1.2.1` released - Added support for `PR`/`Puerto Rico`[[1](https://github.com/hrbrmstr/statebins/issues/2)] and fixed a bug[[2](https://github.com/hrbrmstr/statebins/issues/3)] when using anything but a `data.frame` as input. Also no longer fails (deals with the following but with a warning) when duplicate states are in the input data or invalid states are in the input data.
- 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.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)
statebins - U.S. State Cartogram Heatmaps in R; 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:
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` - 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_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
- `statebins_manual` - creates "statebin" charts using manually specified colors in a column
### TODO
### TODO
- The current version is usable, but I think the plot margins and the legends need work
- The current version is usable, but I think the plot margins and the legends need work
- Apply algorithm to switch to light-on-dark depending on the background tile color
- Apply algorithm to switch to light-on-dark depending on the background tile color
### News
### News
- Version `1.2.1` released - Added support for `PR`/`Puerto Rico`[[1](https://github.com/hrbrmstr/statebins/issues/2)] and fixed a bug[[2](https://github.com/hrbrmstr/statebins/issues/3)] when using anything but a `data.frame` as input. Also no longer fails (deals with the following but with a warning) when duplicate states are in the input data or invalid states are in the input data.
- Version `1.2.1` released - Added support for `PR`/`Puerto Rico`[[1](https://github.com/hrbrmstr/statebins/issues/2)] and fixed a bug[[2](https://github.com/hrbrmstr/statebins/issues/3)] when using anything but a `data.frame` as input. Also no longer fails (deals with the following but with a warning) when duplicate states are in the input data or invalid states are in the input data.
- 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.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
- Version `1.0.0` released
### Installation
### Installation
``` r
```r
devtools::install_github("hrbrmstr/statebins")
devtools::install_github("hrbrmstr/statebins")
```
```
### Usage
### 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 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).
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
```r
library(statebins)
library(statebins)
# current verison
# current verison
packageVersion("statebins")
packageVersion("statebins")
```
```
## [1] '1.2.1'
```
## [1] '1.2.2'
```
``` r
```r
# the original wapo data
# 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)
dat <-read.csv("http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/states.csv?cache=1",stringsAsFactors=FALSE)
\item{state_data}{data frame of states and values to plot}
\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. "\code{Maine}") or abbreviatons (e.g. "\code{ME}")}
\item{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}")}
\item{value_col}{column name in \code{state_data} that holds the values to be plotted}
\item{value_col}{column name in \code{state_data} that holds the values to be plotted}
\item{state_border_col}{default "\code{white}" - this creates the "spaces" between boxes}
\item{state_border_col}{default "\code{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{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{labels}{labels for the levels \code{breaks}}
\item{legend_title}{title for the legend}
\item{legend_title}{title for the legend}
\item{legend_position}{"\code{none}", "\code{top}", "\code{left}", "\code{right}" or "\code{bottom}" (defaults to "\code{top}")}
\item{legend_position}{"\code{none}", "\code{top}", "\code{left}", "\code{right}" or
"\code{bottom}" (defaults to "\code{top}")}
\item{brewer_pal}{which named \link{RColorBrewer} palette to use (defaults to "PuBu")}
\item{brewer_pal}{which named \code{RColorBrewer} palette to use (defaults to "PuBu")}
\item{plot_title}{title for the plot}
\item{plot_title}{title for the plot}
\item{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}
\item{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}
}
}
\value{
\value{
ggplot2 object or grob
ggplot2 object or grob
@ -44,23 +48,24 @@ ggplot2 object or grob
\code{statebins()} creates "statebin" charts in the style of \url{http://bit.ly/statebins}
\code{statebins()} creates "statebin" charts in the style of \url{http://bit.ly/statebins}
}
}
\details{
\details{
This version uses discrete \link{RColorBrewer} scales, binned by the "breaks" parameter.
This version uses discrete \code{RColorBrewer} scales, binned by the "breaks" parameter.
The function minimally expects the caller to pass in a data frame that:
The function minimally expects the caller to pass in a data frame that:
\itemize{
\itemize{
\item has one column of all state abbreviationis (all caps, including \code{DC} & \code{PR} or a column of state names (standard capitalization) named \code{state}
\item has one column of all state abbreviationis (all caps, including \code{DC} &
\code{PR} or a column of state names (standard capitalization) named \code{state}
\item has another column of values named \code{value}
\item has another column of values named \code{value}
}
}
Doing so will create a "statebin" chart with 5 breaks and return a \link{ggplot2} object.
Doing so will create a "statebin" chart with 5 breaks and return a ggplot2 object.
You can use a different column for the state names and values by changing \code{state_col}
You can use a different column for the state names and values by changing \code{state_col}
and \code{value_col} accordingly.
and \code{value_col} accordingly.
To add a title, change \code{plot_title} to anything but an empty atomic string vector (i.e. \code{""})
To add a title, change \code{plot_title} to anything but an empty atomic string vector (i.e. \code{""})
and set \code{title_position} 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
will cause \code{statebins} to use \code{arrangeGrob} to position the title via \code{sub} and
\item{state_data}{data frame of states and values to plot}
\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. "\code{Maine}") or abbreviatons (e.g. "\code{ME}")}
\item{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}")}
\item{value_col}{column name in \code{state_data} that holds the values to be plotted}
\item{value_col}{column name in \code{state_data} that holds the values to be plotted}
\item{legend_position}{"\code{none}", "\code{top}", "\code{left}", "\code{right}" or "\code{bottom}" (defaults to "\code{top}")}
\item{legend_position}{"\code{none}", "\code{top}", "\code{left}", "\code{right}" or
"\code{bottom}" (defaults to "\code{top}")}
\item{brewer_pal}{which named \link{RColorBrewer} palette to use (defaults to "PuBu")}
\item{brewer_pal}{which named \code{RColorBrewer} palette to use (defaults to "PuBu")}
\item{plot_title}{title for the plot}
\item{plot_title}{title for the plot}
\item{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}
\item{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}
}
}
\value{
\value{
ggplot2 object or grob
ggplot2 object or grob
@ -39,24 +42,25 @@ ggplot2 object or grob
\code{statebins()} creates "statebin" charts in the style of \url{http://bit.ly/statebins}
\code{statebins()} creates "statebin" charts in the style of \url{http://bit.ly/statebins}
}
}
\details{
\details{
This version uses a continuous scale based on \link{RColorBrewer} scales
This version uses a continuous scale based on \code{RColorBrewer} scales
(passing in a 6 element \code{RColorBrewer} palette to \link{scale_fill_gradientn}).
(passing in a 6 element \code{RColorBrewer} palette to \code{scale_fill_gradientn}).
The function minimally expects the caller to pass in a data frame that:
The function minimally expects the caller to pass in a data frame that:
\itemize{
\itemize{
\item has one column of all state abbreviationis (all caps, including \code{DC} & \code{PR} ) or a column of state names (standard capitalization) named \code{state}
\item has one column of all state abbreviationis (all caps, including \code{DC} &
\code{PR} ) or a column of state names (standard capitalization) named \code{state}
\item has another column of values named \code{value}
\item has another column of values named \code{value}
}
}
Doing so will create a "statebin" chart with 5 breaks and return a \link{ggplot2} object.
Doing so will create a "statebin" chart with 5 breaks and return a \code{ggplot2} object.
You can use a different column for the state names and values by changing \code{state_col}
You can use a different column for the state names and values by changing \code{state_col}
and \code{value_col} accordingly.
and \code{value_col} accordingly.
To add a title, change \code{plot_title} to anything but an empty atomic string vector (i.e. \code{""})
To add a title, change \code{plot_title} to anything but an empty atomic string vector (i.e. \code{""})
and set \code{title_position} 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
will cause \code{statebins} to use \code{arrangeGrob} to position the title via \code{sub} and
\item{state_data}{data frame of states and values to plot}
\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. "\code{Maine}") or abbreviatons (e.g. "\code{ME}")}
\item{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}")}
\item{color_col}{column name in \code{state_data} that holds the colors to be used}
\item{color_col}{column name in \code{state_data} that holds the colors to be used}
\item{state_border_col}{default "\code{white}" - this creates the "spaces" between boxes}
\item{state_border_col}{default "\code{white}" - this creates the "spaces" between boxes}
\item{labels}{labels for the legend (should be the same number as distinct colors in \code{color_col}); \code{NULL} == no labels/legend}
\item{labels}{labels for the legend (should be the same number as distinct colors in
\code{color_col}); \code{NULL} == no labels/legend}
\item{legend_title}{title for the legend}
\item{legend_title}{title for the legend}
\item{legend_position}{"\code{none}", "\code{top}", "\code{left}", "\code{right}" or "\code{bottom}" (defaults to "\code{top}")}
\item{legend_position}{"\code{none}", "\code{top}", "\code{left}", "\code{right}" or
"\code{bottom}" (defaults to "\code{top}")}
\item{plot_title}{title for the plot}
\item{plot_title}{title for the plot}
\item{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}
\item{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}
}
}
\value{
\value{
ggplot2 object or grob
ggplot2 object or grob
@ -44,28 +48,36 @@ This version uses manual colors (i.e. pass in a column that defines the color pe
The function minimally expects the caller to pass in a data frame that:
The function minimally expects the caller to pass in a data frame that:
\itemize{
\itemize{
\item has one column of all state abbreviationis (all caps, including \code{DC} & \code{PR} or a column of state names (standard capitalization) named \code{state}
\item has one column of all state abbreviationis (all caps, including \code{DC} &
\code{PR} or a column of state names (standard capitalization) named \code{state}
\item has another column of colors named \code{color}
\item has another column of colors named \code{color}
}
}
Doing so will create a "statebin" chart with the colors specified as a \link{ggplot2} object.
Doing so will create a "statebin" chart with the colors specified as a ggplot2 object.
You can use a different column for the state names and colors by changing \code{state_col}
You can use a different column for the state names and colors by changing \code{state_col}
and \code{color_col} accordingly.
and \code{color_col} accordingly.
To add a title, change \code{plot_title} to anything but an empty atomic string vector (i.e. \code{""})
To add a title, change \code{plot_title} to anything but an empty atomic string vector (i.e. \code{""})
and set \code{title_position} 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
will cause \code{statebins} to use \code{arrangeGrob} to position the title via \code{sub} and