Skip to contents

Creates an object with data and coordinates of class EU for European countries to use with mapping functions or available in other R "maps" packages.

Usage

EU(data, colID = NULL,
               unit = c("nuts0","nuts1", "nuts2", "nuts3", "urau"),
               year = c("2021","2016", "2013", "2010", "2006", "2003"),
               matchWith = c("nuts", "id", "iso2", "iso3", "country_code"),
               scale = c("20", "60"), show_eu = TRUE,
               subset = NULL, add = NULL, new_var_names = NULL,
               aggregation_fun = sum, aggregation_unit = NULL, aggregation_var = NULL,
               facets = NULL, check.unit.names = TRUE, dir = NULL,
               use_cache = TRUE, print = FALSE, use_internet = TRUE, crs = NULL)

Arguments

data

a data.frame object with variables to display

colID

character value or columns number indicating the column with unit names

unit

the type of European statistical unit

year

year of the analysis

matchWith

the type of id to check:

"nuts"if nuts names
"id"if nuts id
"iso2"if iso2 code
"iso3"if iso3 code
"country_code"if Eurostat code
scale

the scale of the map

show_eu

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

subset

a formula indicating the condition to subset the data, see the Details

add

a formula to add new transformed variables starting from the variables in the data

new_var_names

a character value or vector indicating the names of the new variables created in add

aggregation_fun

function to use when data are aggregated

aggregation_unit

variable name by which the unit are aggregated

aggregation_var

variable name with value to aggregate

facets

variable(s) name to split the data

check.unit.names

a logical value indicating if the colID names are checked with unit names

dir

local directory in which shape files are stored

use_cache

a logical value indicating whether use the cache

print

a logical value indicating whether print the nomatched names

use_internet

a logical value indicating wheter the coordinates are downloaded from https://github.com/mappinguniverse/geospatial. If FALSE the maps downloaded during package installation will be used.

crs

coordinate reference system. Look at st_crs

Details

The function links (automatically) the id in the data and the coordinates for the given unit.

Since the names (or codes) provided in the data given in input must be checked with the unit names (or codes) available in the package (as provided by Eurostat), the check.unit.names provides a preliminary check.

subset provide an expression to subset the data, using a formula with the logical operators. For example, sub-samples of the data can be selected as follows: ~I("Variable 1" == "condition 1" & "Variable 2" != "condition 2") or for example, ~I("Variable 1" > "condition 1" | "Variable 2" != "condition 2").

Value

An object of class EU, with data and coordinates to use in functions which perform map.

See also

WR, IT, US, DE, UK

Examples


data("popEU")

popEU <- popEU

euNuts2 <- EU(data = popEU, colID = "GEO",
              unit = "nuts2",matchWith = "id")
str(euNuts2)
#> Classes ‘sf’, ‘EU’, ‘EU’ and 'data.frame':	328 obs. of  16 variables:
#>  $ GEO         : chr  "cz05" "cz06" "cz07" "cz08" ...
#>  $ country     : chr  "Czechia" "Czechia" "Czechia" "Czechia" ...
#>  $ iso2        : chr  "CZ" "CZ" "CZ" "CZ" ...
#>  $ iso3        : chr  "CZE" "CZE" "CZE" "CZE" ...
#>  $ country_code: int  203 203 203 203 276 276 276 276 276 276 ...
#>  $ nuts0_id    : chr  "CZ" "CZ" "CZ" "CZ" ...
#>  $ nuts1_id    : chr  "CZ0" "CZ0" "CZ0" "CZ0" ...
#>  $ nuts2_id    : chr  "CZ05" "CZ06" "CZ07" "CZ08" ...
#>  $ nuts0       : chr  "Czechia" "Czechia" "Czechia" "Czechia" ...
#>  $ nuts1       : chr  "Česko" "Česko" "Česko" "Česko" ...
#>  $ nuts2       : chr  "Severovýchod" "Jihovýchod" "Střední Morava" "Moravskoslezsko" ...
#>  $ TIME        : num  2019 2019 2019 2019 2019 ...
#>  $ total       : num  1513693 1696941 1215413 1203299 4143418 ...
#>  $ male        : num  747330 835577 595503 590516 2067094 ...
#>  $ female      : num  766363 861364 619910 612783 2076324 ...
#>  $ geometry    :sfc_MULTIPOLYGON of length 328; first list element: List of 1
#>   ..$ :List of 1
#>   .. ..$ : num [1:38, 1:2] 15.4 15.2 15.1 15 14.8 ...
#>   ..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"
#>  - attr(*, "sf_column")= chr "geometry"
#>  - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
#>   ..- attr(*, "names")= chr [1:15] "GEO" "country" "iso2" "iso3" ...
#>  - attr(*, "unit")= chr "nuts2"
#>  - attr(*, "year")= chr "2021"
#>  - attr(*, "colID")= chr "GEO"

# \donttest{


euNuts2_1 <- EU(data = popEU, colID = "GEO",
                unit = "nuts2",matchWith = "id",
                add = ~I(male/total) + I(female/total))
str(euNuts2_1)
#> Classes ‘sf’, ‘EU’, ‘EU’ and 'data.frame':	328 obs. of  18 variables:
#>  $ GEO            : chr  "cz05" "cz06" "cz07" "cz08" ...
#>  $ country        : chr  "Czechia" "Czechia" "Czechia" "Czechia" ...
#>  $ iso2           : chr  "CZ" "CZ" "CZ" "CZ" ...
#>  $ iso3           : chr  "CZE" "CZE" "CZE" "CZE" ...
#>  $ country_code   : int  203 203 203 203 276 276 276 276 276 276 ...
#>  $ nuts0_id       : chr  "CZ" "CZ" "CZ" "CZ" ...
#>  $ nuts1_id       : chr  "CZ0" "CZ0" "CZ0" "CZ0" ...
#>  $ nuts2_id       : chr  "CZ05" "CZ06" "CZ07" "CZ08" ...
#>  $ nuts0          : chr  "Czechia" "Czechia" "Czechia" "Czechia" ...
#>  $ nuts1          : chr  "Česko" "Česko" "Česko" "Česko" ...
#>  $ nuts2          : chr  "Severovýchod" "Jihovýchod" "Střední Morava" "Moravskoslezsko" ...
#>  $ TIME           : num  2019 2019 2019 2019 2019 ...
#>  $ total          : num  1513693 1696941 1215413 1203299 4143418 ...
#>  $ male           : num  747330 835577 595503 590516 2067094 ...
#>  $ female         : num  766363 861364 619910 612783 2076324 ...
#>  $ I.male.total.  : 'AsIs' num  0.493713.... 0.492401.... 0.489959.... 0.490747.... 0.498886.... ...
#>  $ I.female.total.: 'AsIs' num  0.506286.... 0.507598.... 0.510040.... 0.509252.... 0.501113.... ...
#>  $ geometry       :sfc_MULTIPOLYGON of length 328; first list element: List of 1
#>   ..$ :List of 1
#>   .. ..$ : num [1:38, 1:2] 15.4 15.2 15.1 15 14.8 ...
#>   ..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"
#>  - attr(*, "sf_column")= chr "geometry"
#>  - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
#>   ..- attr(*, "names")= chr [1:17] "GEO" "country" "iso2" "iso3" ...
#>  - attr(*, "unit")= chr "nuts2"
#>  - attr(*, "year")= chr "2021"
#>  - attr(*, "colID")= chr "GEO"

euNuts2_2 <- EU(data = popEU, colID = "GEO",
                unit = "nuts2",matchWith = "id",
                add = ~I(male/total) + I(female/total),
                new_var_names = c("Per_Male", "Per_Female"))
str(euNuts2_2)
#> Classes ‘sf’, ‘EU’, ‘EU’ and 'data.frame':	328 obs. of  18 variables:
#>  $ GEO         : chr  "cz05" "cz06" "cz07" "cz08" ...
#>  $ country     : chr  "Czechia" "Czechia" "Czechia" "Czechia" ...
#>  $ iso2        : chr  "CZ" "CZ" "CZ" "CZ" ...
#>  $ iso3        : chr  "CZE" "CZE" "CZE" "CZE" ...
#>  $ country_code: int  203 203 203 203 276 276 276 276 276 276 ...
#>  $ nuts0_id    : chr  "CZ" "CZ" "CZ" "CZ" ...
#>  $ nuts1_id    : chr  "CZ0" "CZ0" "CZ0" "CZ0" ...
#>  $ nuts2_id    : chr  "CZ05" "CZ06" "CZ07" "CZ08" ...
#>  $ nuts0       : chr  "Czechia" "Czechia" "Czechia" "Czechia" ...
#>  $ nuts1       : chr  "Česko" "Česko" "Česko" "Česko" ...
#>  $ nuts2       : chr  "Severovýchod" "Jihovýchod" "Střední Morava" "Moravskoslezsko" ...
#>  $ TIME        : num  2019 2019 2019 2019 2019 ...
#>  $ total       : num  1513693 1696941 1215413 1203299 4143418 ...
#>  $ male        : num  747330 835577 595503 590516 2067094 ...
#>  $ female      : num  766363 861364 619910 612783 2076324 ...
#>  $ Per_Male    : 'AsIs' num  0.493713.... 0.492401.... 0.489959.... 0.490747.... 0.498886.... ...
#>  $ Per_Female  : 'AsIs' num  0.506286.... 0.507598.... 0.510040.... 0.509252.... 0.501113.... ...
#>  $ geometry    :sfc_MULTIPOLYGON of length 328; first list element: List of 1
#>   ..$ :List of 1
#>   .. ..$ : num [1:38, 1:2] 15.4 15.2 15.1 15 14.8 ...
#>   ..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"
#>  - attr(*, "sf_column")= chr "geometry"
#>  - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
#>   ..- attr(*, "names")= chr [1:17] "GEO" "country" "iso2" "iso3" ...
#>  - attr(*, "unit")= chr "nuts2"
#>  - attr(*, "year")= chr "2021"
#>  - attr(*, "colID")= chr "GEO"
# }