mappingWR: Static maps for World countries

View source: R/mappingWR.R

mappingWRR Documentation

Static maps for World countries

Description

Function to produce static maps for world countries.

Usage

mappingWR(data, var = NULL, colID = NULL,
          type = c("static", "interactive"),
          typeStatic = c("tmap", "choro.cart",
                         "typo", "bar"),
          unit = c("country", "nato", "ocde", "continent",
                   "region", "subregion", "region_wb",
                   "type_income", "type_economy"),
          matchWith = c("country", "iso2", "iso3",
                        "iso3_eh", "iso3_numeric",
                        "iso3_un", "iso2_wb", "iso3_wb",
                        "name_formal", "name_wb"),
          res = c("low", "hi"), dir = NULL, show_wr = TRUE,
          add_text = NULL, subset = NULL,
          facets = NULL, aggregation_fun = sum, aggregation_unit = NULL,
          options = mapping.options(legend.position = c("left", "bottom")))

Arguments

data

a data.frame object with variables to display or a WR object produced by WR function

var

character value(s) or columns number(s) indicating the variable to plot

colID

character value or columns number indicating the column with unit names

type

if generates static or interactive map

typeStatic

type of static map

unit

the type of world statistical unit

matchWith

the type of id to check:

"country" if country names).
"iso2" if iso2 code.
"iso3" if iso3 code.
"iso3_eh" if iso3_eh code.
"iso3_numeric" if iso3 numeric code.
"iso3_un" if iso3 United Nations.
"iso2_wb" if iso2 World Bank.
"iso3_wb" if iso3 World Bank.
"name_formal" if formal names.
"name_wb" if World Bank names.
res

map resolution

dir

local directory in which shape files are stored

show_wr

logical value set to TRUE indicating if the map entire map is drawn or only the coordinates linked to the input data

add_text

character name indicating the column with text labels

subset

a formula indicating the condition to subset the data. See the details section

facets

variable(s) name to split the data

aggregation_fun

function to use when data are aggregated

aggregation_unit

variable name by which the unit are aggregated

options

a list with options using mapping.options function

Details

If data is a object of class "WR" generated using the WR 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.

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").

Value

Return a map. For tmap type, the function also returns a tmap object.

References

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). “tmap: Thematic Maps in R.” _Journalstatisticaltical Software_, *84*(6), 1-39. doi: 10.18637/jss.v084.i06 (URL: https://doi.org/10.18637/jss.v084.i06).

See Also

mappingEU,mappingIT,mappingUS,mappingDE,mappingUK

Examples


data("popWR")
popWR <- popWR


wr <- WR(data = popWR, colID = "country_code",
         matchWith = "iso3_eh", check.unit.names = FALSE,
         res = "low")

###############
#   Statics   #
###############


mappingWR(data = wr, var = "total")


mappingWR(data = wr, var = c("male","female"))
mappingWR(data = wr, var = "total", subset = ~I(iso2 == "IT"))
mappingWR(data = wr, var = "total", subset = ~I(region == "Americas"))

mappingWR(data = wr, var = "total", facets = "continent")
mappingWR(data = wr, var = "total",
          subset = ~I(continent == "South America"),
          facets = "name_wb")



mappingWR(data = wr, var = "total", typeStatic = "choro.cart")


mappingWR(data = wr, var = "total", aggregation_unit = "continent",
          aggregation_fun = function(x) sum(x, na.rm = TRUE))
mappingWR(data = wr, var = "total", aggregation_unit = "subregion",
          aggregation_fun = function(x) sum(x, na.rm = TRUE))

## World countries

wr1 <- loadCoordWR()
mappingWR(data = wr1)


###############
# Interactive #
###############


mappingWR(data = wr, var = "total", type = "interactive")
mappingWR(data = wr, var = c("male","female"), type = "interactive")
mappingWR(data = wr, var = "total", subset = ~I(iso2 == "IT"), type = "interactive")



mappingWR(data = wr, var = "total",
          subset = ~I(region == "Americas"), type = "interactive")
mappingWR(data = wr, var = "total", type = "interactive",
          aggregation_unit = "continent",
          aggregation_fun = function(x) sum(x, na.rm = TRUE))
mappingWR(data = wr, var = "total", type = "interactive",
          aggregation_unit = "subregion",
          aggregation_fun = function(x) sum(x, na.rm = TRUE))



mapping documentation built on Oct. 19, 2023, 5:06 p.m.