Skip to contents

Get Autonomous Communities and Cities of Spain at a specified scale.

Usage

esp_get_ccaa(ccaa = NULL, moveCAN = TRUE, ...)

Arguments

ccaa

Character string. A vector of names, codes or both for Autonomous Communities and Cities, or NULL to get all Autonomous Communities and Cities. See Details.

moveCAN

A logical TRUE/FALSE or a vector of coordinates c(lat, lon). It places the Canary Islands close to Spain's mainland. Initial position can be adjusted using the vector of coordinates. See Displacing the Canary Islands in esp_move_can().

...

Arguments passed on to esp_get_nuts

year

Year character string or number. Release year of the file. See giscoR::gisco_get_nuts() for valid values.

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

cache

Logical. Whether to cache downloaded files. Defaults to TRUE. See Caching.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

spatialtype

Character string. Type of geometry to be returned. Options available are:

  • "RG": regions, returned as a MULTIPOLYGON/POLYGON object.

  • "LB": labels, returned as a POINT object.

ext

Character. Extension of the file (default "gpkg"). See giscoR::gisco_get_nuts().

verbose

A logical value. If TRUE displays informational messages.

resolution

A character string or numeric value with the geospatial data resolution. One of:

  • "60": 1:60 million.

  • "20": 1:20 million.

  • "10": 1:10 million.

  • "03": 1:3 million.

  • "01": 1:1 million.

Value

A sf object.

Details

When using ccaa you can use and mix names and NUTS codes (levels 1 or 2), ISO codes (corresponding to level 2) or codauto (see esp_codelist). Ceuta and Melilla are included at the Autonomous Communities and Cities level in this function.

When calling a NUTS 1 level, all Autonomous Communities and Cities of that level are added.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

See also

Examples

ccaa <- esp_get_ccaa()

library(ggplot2)

ggplot(ccaa) +
  geom_sf()


# Random Autonomous Communities and Cities.
random_ccaa <- esp_get_ccaa(ccaa = c(
  "Euskadi",
  "Catalunya",
  "ES-EX",
  "Canarias",
  "ES52",
  "01"
))

ggplot(random_ccaa) +
  geom_sf(aes(fill = codauto), show.legend = FALSE) +
  geom_sf_label(aes(label = codauto), alpha = 0.3) +
  coord_sf(crs = 3857)


# All Autonomous Communities and Cities of a NUTS 1 region plus one.

mixed <- esp_get_ccaa(ccaa = c("La Rioja", "Noroeste"))

ggplot(mixed) +
  geom_sf()


# Combine with giscoR to get countries.
# \donttest{

library(giscoR)
library(sf)
#> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.4.0; sf_use_s2() is TRUE

res <- 20 # Use the same resolution.

europe <- gisco_get_countries(resolution = res)
ccaa <- esp_get_ccaa(moveCAN = FALSE, resolution = res)

ggplot(europe) +
  geom_sf(fill = "#DFDFDF", color = "#656565") +
  geom_sf(data = ccaa, fill = "#FDFBEA", color = "#656565") +
  coord_sf(
    xlim = c(23, 74) * 10e4,
    ylim = c(14, 55) * 10e4,
    crs = 3035
  ) +
  theme(panel.background = element_rect(fill = "#C7E7FB"))

# }