choropleth.state: State level choropleth

View source: R/choropleth.state.R

choropleth.stateR Documentation

State level choropleth

Description

Creates choropleth at the U.S. state level.

Usage

choropleth.state(
  df,
  state.column = "state",
  value.column = "value",
  legend.title = "",
  legend.text.size = 20,
  scale.text.size = 16,
  color.domain = NULL,
  num.legend.ticks = 5,
  color.scheme = c("Blues", names(d3po::color.schemes)),
  width = NULL,
  height = NULL,
  viewer = c("internal", "external", "browser")
)

Arguments

df

data.frame containing value data by state.

state.column

Name of column containing state names. Defaults to "state". All values in this column must match c(datasets::state.name, "District of Columbia").

value.column

Name of column containing values by state. Defaults to "value".

legend.title

Title of legend, e.g., units. Defaults to "".

legend.text.size

Size of text (in points) for legend. Defaults to 20.

scale.text.size

Size of text (in points) for the scale values. Defaults to 16.

color.domain

Range of values for the color scale. Defaults to c(min(df[,value.column]), max(df[,value.column])). Length greater than two results in a multi-point gradient.

num.legend.ticks

Number of breaks in legend scale. Defaults to 5.

color.scheme

Color scheme to use in visualization. See color.schemes for more details.

width

Desired width for output widget.

height

Desired height for output widget.

viewer

"internal" to use the RStudio internal viewer pane for output; "external" to display in an external RStudio window; "browser" to display in an external browser.

Details

Utilizes a script similar to https://observablehq.com/@d3/state-choropleth adapted to work with r2d3.

Value

A d3 object as returned by r2d3.

Examples

data(unemployment.state)

choropleth.state(unemployment.state,
                 state.column = "name",
                 value.column = "rate",
                 legend.title = "Unemployment rate (%)")


tkmckenzie/d3po documentation built on June 2, 2022, 2:41 p.m.