statebins: Create a new ggplot-based "statebin" chart for USA states...

Description Usage Arguments Details Value Examples

View source: R/statebins.R

Description

statebins() creates "statebin" charts in the style of http://bit.ly/statebins

Usage

1
2
3
4
5
statebins(state_data, state_col = "state", value_col = "value",
  text_color = "black", 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")

Arguments

state_data

data frame of states and values to plot

state_col

column name in state_data that has the states. no duplicates and can be names (e.g. "Maine") or abbreviatons (e.g. "ME")

value_col

column name in state_data that holds the values to be plotted

text_color

default "black"

font_size

font size (default = 3)

state_border_col

default "white" - this creates the "spaces" between boxes

breaks

a single number (greater than or equal to 2) giving the number of intervals into which data values are to be cut.

labels

labels for the levels breaks

legend_title

title for the legend

legend_position

"none", "top", "left", "right" or "bottom" (defaults to "top")

brewer_pal

which named RColorBrewer palette to use (defaults to "PuBu")

plot_title

title for the plot

title_position

where to put the title ("bottom" or "top" or "" for none); if "bottom", you get back a grob vs a ggplot object

Details

This version uses discrete RColorBrewer scales, binned by the "breaks" parameter.

The function minimally expects the caller to pass in a data frame that:

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 state_col and value_col accordingly.

To add a title, change plot_title to anything but an empty atomic string vector (i.e. "") and set title_position to "top" or "bottom". Choosing "bottom" will cause statebins to use arrangeGrob to position the title via sub and return a frame grob instead of a ggplot2 object.

Value

ggplot2 object or grob

Examples

1
2
3
4
5
6
7
## Not run: 
data(USArrests)
USArrests$state <- rownames(USArrests)
statebins(USArrests, value_col="Assault", text_color="black", font_size=3,
          legend_title = "Assault", legend_position="bottom")

## End(Not run)

statebins documentation built on May 30, 2017, 2:25 a.m.