stateMap {MazamaSpatialPlots} | R Documentation |
State level thematic map
Description
Uses the tmap package to generate a thematic map at the
state level. Input consists of a dataframe with stateCode
identifiers.
Data to plot is specified with parameter
argument. If parameter
is mult-valued, mutliple plots will be generated and displayed in a
"small multiples" matrix.
The returned object is a tmap ggplot object which can be further modified with ggplot options.
Usage
stateMap(
data = NULL,
parameter = NULL,
state_SFDF = "USCensusStates_02",
palette = "YlOrBr",
breaks = NULL,
conusOnly = TRUE,
stateCode = NULL,
projection = NULL,
stateBorderColor = "gray50",
title = NULL,
main.title = NULL
)
Arguments
data |
Dataframe containing values to plot. This dataframe
must contain a column named |
parameter |
Name of the column in |
state_SFDF |
simple features data frame with US states. It's data
|
palette |
Palette name or a vector of colors based on RColorBrewer. |
breaks |
Numeric vector of break points. |
conusOnly |
Logical specifying Continental US state codes. Ignored when
the |
stateCode |
Vector of state codes to include on the map. |
projection |
Specified method to represent surface of Earth. |
stateBorderColor |
Color used for state borders. |
title |
Vector of text strings to use as individual plot titles. This must be the same length as 'parameter'. |
main.title |
Text string to use as an overall title for all plots. |
Details
See tmap::tm_fill()
for a more detailed description of
the following parameters:
palette
breaks
Value
A ggplot object.
Examples
library(MazamaSpatialPlots)
stateMap(
data = example_US_stateObesity,
parameter = "obesityRate",
palette = "BuPu",
stateBorderColor = "white",
main.title = "2018 Obesity by State"
)
# Example of customization using tm_layout and breaks parameter
stateMap(
data = example_US_stateObesity,
parameter = "obesityRate",
breaks = seq(20,38,3),
stateBorderColor = 'black'
) +
tmap::tm_layout(
frame = TRUE,
frame.double.line = TRUE,
main.title = 'Obesity Rate by State',
main.title.position = c("center", "top"),
fontfamily = "serif",
bg.color = "grey85",
inner.margins = .05
)
# Example using stateCode
stateMap(
data = example_US_stateObesity,
parameter = "obesityRate",
stateCode = c('ME', 'NH', 'VT', 'MA', 'RI', 'CT'),
stateBorderColor = 'black',
title = 'Obesity Rates in New England'
) +
tmap::tm_layout(
frame = TRUE,
frame.double.line = TRUE,
title.size = 1.2,
title.fontface = 2,
fontfamily = "serif",
bg.color = "grey85",
inner.margins = .08
)