map_with_data | R Documentation |
Join county or state level data to US map data
map_with_data(data, values = "values", include = c(), exclude = c(), na = NA)
data |
The data that should be joined to a US 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 |
include |
The regions to include in the resulting map. If |
exclude |
The regions to exclude in the resulting map. If |
na |
The value to be inserted for states or counties that don't have
a value in |
A data frame composed of the map data frame (from us_map()
) except
an extra column containing the values in data
is included.
The result can be plotted using ggplot2::ggplot()
or plot_usmap()
.
plot_usmap()
state_data <- data.frame(fips = c("01", "02", "04"), values = c(1, 5, 8))
df <- map_with_data(state_data, na = 0)
state_data <- data.frame(state = c("AK", "CA", "Utah"), values = c(6, 9, 3))
df <- map_with_data(state_data, na = 0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.