generate_map | R Documentation |
generate_map
takes CSPP data from get_cspp_data
and plots the
values of numeric variables on the map of the U.S. It can also plot
individual states or sets of states.
cspp_data |
Dataframe generated by |
var_name |
Specify the variable from the dataset passed to
|
average_years |
Default is |
drop_NA_states |
Choose whether to drop states at the map generating
stage which have NA values. Default is If you're passing a dataframe subset to certain states, set this to TRUE. |
poly_args |
Default is |
Note: due to complications with plotting Alaska and Hawaii, this package currently does not support plotting these two states.
This function is general in the sense that it will produce a ggplot-style map for any dataframe passed to it with the proper formatting. Any dataframe that has at least three columns, with the first two a numeric 'year' column and a state name as a string, and the final column the value to be plotted, will work with this function.
Returns a ggplot
object. See examples for how to work with
this object.
get_cspp_data
, get_cites
, get_var_info
## default map with total population generate_map() ## pass specific variables # returns average over all non NA years in the data generate_map(get_cspp_data(var_category = "demographics"), var_name = "pctpopover65") ## add additional ggplot options generate_map(get_cspp_data(var_category = "demographics"), var_name = "pctpopover65", poly_args = list(color = "black"), drop_NA_states = FALSE) + ggplot2::scale_fill_gradient(low = "white", high = "red") + ggplot2::theme(legend.position = "none") + ggplot2::ggtitle("% Population Over 65") ## plot specific states # drop_NA_states set to TRUE plots only those states library(dplyr) generate_map(get_cspp_data(var_category = "demographics") %>% dplyr::filter(st %in% c("NC", "VA", "SC")), var_name = "pctpopover65", poly_args = list(color = "black"), drop_NA_states = TRUE) + ggplot2::scale_fill_gradient(low = "white", high = "red") + ggplot2::theme(legend.position = "none") + ggplot2::ggtitle("% Population Over 65") ## pass specific variables and years # returns average over set of years provided library(dplyr) generate_map(get_cspp_data(var_category = "demographics") %>% dplyr::filter(year %in% seq(2001, 2010))) # returns average over set of years provided library(dplyr) generate_map(get_cspp_data(var_category = "demographics") %>% dplyr::filter(year %in% seq(2001, 2010)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.