statebins_continuous: 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
statebins_continuous(state_data, state_col = "state", value_col = "value",
  text_color = "black", font_size = 3, state_border_col = "white",
  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

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 a continuous scale based on RColorBrewer scales (passing in a 6 element RColorBrewer palette to scale_fill_gradientn).

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_continuous(USArrests, value_col="Murder", text_color="black", font_size=3,
                     legend_title = "Murder", legend_position="bottom")

## End(Not run)

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