knitr::opts_chunk$set(echo = TRUE, collapse = TRUE, 
                      fig.width = 7, fig.height = 4,
                      fig.align = "center", message = FALSE, warning = FALSE)

The CRAN version can be loaded as follows:

library('mapping')

or the development version from GitHub:

remotes::install_github('serafinialessio/mapping')

The objects created in this package build the hierarchy starting from the statistical units in input to the larger statistical unit aggregate (look at the other vignettes for more details about the hierarchy).

Aggregations arguments allows to easily aggregate and mapping larger units starting from those given in input.

Italian Examples

data("popIT")
it_pr <- IT(data = popIT, unit = "provincia", year = "2019", check.unit.names = FALSE)
str(it_pr,1)

In the structure we have bigger units, as regione

mappingIT(data = it_pr, var = "totale")
mappingIT(data = it_pr, var = "totale", type = "interactive")

Aggregating the province in the beloging regions summing the total population of each province

mappingIT(data = it_pr, var = "totale", aggregation_unit = "regione")
mappingIT(data = it_pr, var = "totale", aggregation_unit = "regione", type = "interactive")

or for each ripartizione, removing the missing values

mappingIT(data = it_pr, var = "totale", 
          aggregation_unit = "ripartizione", 
          aggregation_fun = function(x) sum(x, na.rm = TRUE))

mappingIT(data = it_pr, var = "totale", 
          aggregation_unit = "ripartizione", 
          aggregation_fun = function(x) sum(x, na.rm = TRUE),
          type = "interactive")

This can be also used with facetes

mappingIT(data = it_pr, var = "totale", 
          aggregation_unit = "regione", facets = "regione")

mappingIT(data = it_pr, var = "totale", 
          aggregation_unit = "regione", facets = "regione",
          type = "interactive")

mappingIT(data = it_pr, var = "totale", 
          aggregation_unit = "ripartizione", facets = "ripartizione", 
          aggregation_fun = function(x) sum(x, na.rm = TRUE))

mappingIT(data = it_pr, var = "totale", 
          aggregation_unit = "ripartizione", facets = "ripartizione", 
          aggregation_fun = function(x) sum(x, na.rm = TRUE),
          type = "interactive")

Also in the facetes we can chose the aggregation

mappingIT(data = it_pr, var = "totale", 
          aggregation_unit = "regione", facets = "ripartizione")

mappingIT(data = it_pr, var = "totale", 
          aggregation_unit = "regione", facets = "ripartizione",
          type = "interactive")


European Union Example

data("popEU")
popEU <- popEU
euNuts2 <- EU(data = popEU, colID = "GEO",unit = "nuts2",matchWith = "id")
str(euNuts2,1)
mappingEU(data = euNuts2, var = "total")
mappingEU(data = euNuts2, var = "total", type = "interactive")

Aggregating the nuts 0 in the belonging countries with the average population of each nuts 0

mappingEU(data = euNuts2, var = "total", 
          aggregation_unit = "nuts0", aggregation_fun = mean)

mappingEU(data = euNuts2, var = "total", 
          aggregation_unit = "nuts0", aggregation_fun = mean,
          type = "interactive")

or with a summation to have the country population

mappingEU(data = euNuts2, var = "total", 
          aggregation_unit = "nuts0", aggregation_fun = sum)

mappingEU(data = euNuts2, var = "total", 
          aggregation_unit = "nuts0", aggregation_fun = sum,
          type = "interactive")

We have many countries and the facetes can be visualise well. At this point we can subset, France for example, and show the nuts 1 units.

mappingEU(data = euNuts2, var = "total", subset = ~I(iso3 == "FRA"),
          aggregation_unit = "nuts1", aggregation_fun = sum, facets = "nuts1")
mappingEU(data = euNuts2, var = "total", subset = ~I(iso3 == "FRA"),
          aggregation_unit = "nuts1", aggregation_fun = sum, facets = "nuts1",
          type = "interactive")

USA Example

data("popUS")
us <- US(data = popUS, unit = "state")
str(us,1)
mappingUS(data = us, var = "population")

mappingUS(data = us, var = "population", type = "interactive")
mappingUS(data = us, var = "population", 
          aggregation_unit = "region")

mappingUS(data = us, var = "population", 
          aggregation_unit = "region",
          type = "interactive")
mappingUS(data = us, var = "population", 
          aggregation_unit = "region", facets = "region")

mappingUS(data = us, var = "population", 
          aggregation_unit = "region", facets = "region",
          type = "interactive")

World example

data("popWR")
popWR <- popWR
wr <- WR(data = popWR, colID = "country_code",
         matchWith = "iso3_eh", check.unit.names = FALSE,
         res = "low")
str(wr,1)
mappingWR(data = wr, var = "total")
mappingWR(data = wr, var = "total", type = "interactive")

Aggregating by continent

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

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


serafinialessio/mapping documentation built on Jan. 30, 2024, 11:39 a.m.