state_choropleth: Create a choropleth of US States with sensible defaults.

Description Usage Arguments Examples

Description

The map used is state.map in the package choroplethrMaps. See state.regions in the choroplethrMaps package for a data.frame that can help you coerce your regions into the required format.

Usage

1
state_choropleth(df, title = "", legend = "", buckets = 7, zoom = NULL)

Arguments

df

A data.frame with a column named "region" and a column named "value". Elements in the "region" column must exactly match how regions are named in the "region" column in state.map.

title

An optional title for the map.

legend

An optional name for the legend.

buckets

The number of equally sized buckets to places the values in. A value of 1 will use a continuous scale, and a value in [2, 9] will use that many buckets.

zoom

An optional vector of states to zoom in on. Elements of this vector must exactly match the names of states as they appear in the "region" column of ?state.regions.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# demonstrate default parameters - visualization using 7 equally sized buckets
data(df_pop_state)
state_choropleth(df_pop_state, title="US 2012 State Population Estimates", legend="Population")

# demonstrate continuous scale and zoom
data(df_pop_state)
state_choropleth(df_pop_state,
                 title="US 2012 State Population Estimates",
                 legend="Population",
                 buckets=1,
                 zoom=c("california", "oregon", "washington"))

# demonstrate how choroplethr handles character and factor values
# demonstrate user creating their own discretization of the input
data(df_pop_state)
df_pop_state$str = ""
for (i in 1:nrow(df_pop_state))
{
  if (df_pop_state[i,"value"] < 1000000)
  {
    df_pop_state[i,"str"] = "< 1M"
  } else {
    df_pop_state[i,"str"] = "> 1M"
  }
}
df_pop_state$value = df_pop_state$str
state_choropleth(df_pop_state, title="Which states have less than 1M people?")

trulia/choroplethr documentation built on June 1, 2019, 1:52 a.m.