
Function to produce static maps for USA unit.
mappingUS(data, var = NULL, colID = NULL,
type = c("static", "interactive"),
typeStatic = c("tmap", "choro.cart", "typo", "bar"),
unit = c("country", "region", "division","state",
"county", "district", "district_county", "urban_area"),
year = c("2018"), matchWith = c("name", "id", "number"),
scale = c("20", "50", "500"), dir = NULL, show_us = TRUE,
add_text = NULL, subset = NULL, facets = NULL,
aggregation_fun = sum, aggregation_unit = NULL,
options = mapping.options())
a data.frame object with variables to display or a US
object produced by US
function
character value(s) or columns number(s) indicating the variable to plot
character value or columns number indicating the column with unit names
if generates static or interactive map
type of static map
the type of European statistical unit to check.
year of the unit
the type of id to check if unit is set to "states"
the scale of a map
local directory in which shape files are stored
logical value set to TRUE indicating if the map entire map is drawn or only the coordinates linked to the input data
character name indicating the column with text labels
a formula indicating the condition to subset the data. See the details section
variable(s) name to split the data
function to use when data are aggregated
variable name by which the unit are aggregated
a list with options using mapping.options
function
Return a map. For tmap
type, the function also returns a tmap
object.
If data
is a object of class "US" generated using the US
function, the arguments unit
, year
, and matchWith
are ignored, because the object already contains the coordinates.
The aggregation_unit
provides an aggregation for a user specified variable in data
, or for larger statistical unit, automatically provided when the function link the data
with the coordinates. For example, if data are of type county
, we will have variables for larger aggregate unit, that is state
and region
variables. Look at US
for more details.
subset
provide an expression to subsetting the data
using a formula, with the logical operators. For example data can be subsetting as follows: ~I("Variable 1" == "condition 1" & "Variable 2" != "condition 2")
or for example, ~I("Variable 1" > "condition 1" | "Variable 2" != "condition 2")
.
Giraud, T. and Lambert, N. (2016). cartography: Create and Integrate Maps in your R Workflow. JOSS, 1(4). doi: 10.21105/joss.00054.
Pebesma, E., 2018. Simple Features for R: Standardized Support for Spatial Vector Data. The R Journal 10 (1), 439-446, https://doi.org/10.32614/RJ-2018-009
Tennekes M (2018). <U+201C>tmap: Thematic Maps in R.<U+201D> _Journalstatisticaltical Software_, *84*(6), 1-39. doi: 10.18637/jss.v084.i06 (URL: https://doi.org/10.18637/jss.v084.i06).
# NOT RUN {
data("popUS")
us <- US(data = popUS, unit = "state")
###############
# Statics #
###############
mappingUS(data = us, var = "population")
mappingUS(data = us, var = "population",
subset = ~I(id == "california" | id == "texas"))
mappingUS(data = us, var = "population",
subset = ~I(id == "california" | id == "texas"), facets = "id")
mappingUS(data = us, var = "population", typeStatic = "choro.cart")
# }
# NOT RUN {
###############
# Interactive #
###############
mappingUS(data = us, var = "population", type = "interactive")
mappingUS(data = us, var = "population", type = "interactive",
subset = ~I(id == "california" | id == "texas" | id == "new york" ))
# }
Run the code above in your browser using DataLab