esp_get_gridmap: Hexbin or square grid maps of Spain

esp_get_gridmapR Documentation

Hexbin or square grid maps of Spain

Description

This function loads a hexbin map (sf object) or a map of squares with boundaries of the provinces or Autonomous Communities and Cities of Spain.

Usage

esp_get_hex_prov(prov = NULL)

esp_get_hex_ccaa(ccaa = NULL)

esp_get_grid_prov(prov = NULL)

esp_get_grid_ccaa(ccaa = NULL)

Arguments

prov, ccaa

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

Details

Hexbin (or grid) maps have an advantage over traditional choropleth maps. In choropleths, regions with larger polygons tend to appear more prominent simply because of their size, which introduces visual bias. With hexbin maps, each region is represented equally, reducing this bias.

You can use and mix names, ISO codes, "codauto" or "cpro" codes (see esp_codelist) and NUTS codes of different levels.

When using a code corresponding to a higher level (for example, esp_get_prov("Andalucia")), all the corresponding units of that level are provided (in this case, all the provinces of Andalusia).

Results are provided in EPSG:4258. Use sf::st_transform() to change the projection.

Value

A sf object.

See Also

Additional boundary datasets and representations: esp_get_comarca(), esp_get_simpl

Examples



esp <- esp_get_spain()
hexccaa <- esp_get_hex_ccaa()

library(ggplot2)

ggplot(hexccaa) +
  geom_sf(data = esp) +
  geom_sf(aes(fill = codauto), alpha = 0.3, show.legend = FALSE) +
  geom_sf_text(aes(label = label), check_overlap = TRUE) +
  theme_void() +
  labs(title = "Hexbin: Autonomous Communities and Cities")

hexprov <- esp_get_hex_prov()

ggplot(hexprov) +
  geom_sf(data = esp) +
  geom_sf(aes(fill = codauto), alpha = 0.3, show.legend = FALSE) +
  geom_sf_text(aes(label = label), check_overlap = TRUE) +
  theme_void() +
  labs(title = "Hexbin: Provinces")

gridccaa <- esp_get_grid_ccaa()

ggplot(gridccaa) +
  geom_sf(data = esp) +
  geom_sf(aes(fill = codauto), alpha = 0.3, show.legend = FALSE) +
  geom_sf_text(aes(label = label), check_overlap = TRUE) +
  theme_void() +
  labs(title = "Grid: Autonomous Communities and Cities")

gridprov <- esp_get_grid_prov()

ggplot(gridprov) +
  geom_sf(data = esp) +
  geom_sf(aes(fill = codauto), alpha = 0.3, show.legend = FALSE) +
  geom_sf_text(aes(label = label), check_overlap = TRUE) +
  theme_void() +
  labs(title = "Grid: Provinces")



mapSpain documentation built on Aug. 31, 2026, 5:07 p.m.