plot_usmap | R Documentation |
Conveniently plot basic US map
plot_usmap(
regions = c("states", "state", "counties", "county"),
include = c(),
exclude = c(),
data = data.frame(),
values = "values",
theme = theme_map(),
labels = FALSE,
label_color = "black",
...
)
regions |
The region breakdown for the map, can be one of
( |
include |
The regions to include in the resulting map. If |
exclude |
The regions to exclude in the resulting map. If |
data |
A data frame containing values to plot on the map. This
parameter should be a data frame consisting of two columns,
a FIPS code (2 characters for state, 5 characters for county)
and the value that should be associated with that region. The
columns of |
values |
The name of the column that contains the values to be associated
with a given region. The default is |
theme |
The theme that should be used for plotting the map. The default
is |
labels |
Whether or not to display labels on the map. Labels are not displayed by default. |
label_color |
The color of the labels to display. Corresponds to the |
... |
Other arguments to pass to |
A ggplot2::ggplot object that contains a basic
US map with the described parameters. Since the result is a ggplot
object, it can be extended with more ggplot2::Geom layers, scales, labels,
themes, etc.
usmap, ggplot2::theme()
plot_usmap()
plot_usmap(regions = "states")
plot_usmap(regions = "counties")
plot_usmap(regions = "state")
plot_usmap(regions = "county")
# Output is ggplot object so it can be extended
# with any number of ggplot layers
library(ggplot2)
plot_usmap(include = c("CA", "NV", "ID", "OR", "WA")) +
labs(title = "Western States")
# Color maps with data
plot_usmap(data = statepop, values = "pop_2022")
# Include labels on map (e.g. state abbreviations)
plot_usmap(data = statepop, values = "pop_2022", labels = TRUE)
# Choose color for labels
plot_usmap(data = statepop, values = "pop_2022", labels = TRUE, label_color = "white")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.