{"id":19070325,"url":"https://github.com/ropenspain/mapspain","last_synced_at":"2025-04-15T18:03:25.976Z","repository":{"id":42015333,"uuid":"310689182","full_name":"rOpenSpain/mapSpain","owner":"rOpenSpain","description":"R package with the administrative boundaries of Spain, including CCAA, provinces and municipalities","archived":false,"fork":false,"pushed_at":"2025-03-18T21:20:21.000Z","size":1118170,"stargazers_count":42,"open_issues_count":4,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-15T18:02:32.952Z","etag":null,"topics":["administrative-boundaries","ccaa","cran","ggplot2","gis","gisco","ign","maps","municipalities","provinces","r","r-package","ropenspain","rstats","spain","spatial","static-tiles","tiles"],"latest_commit_sha":null,"homepage":"https://ropenspain.github.io/mapSpain/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rOpenSpain.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":"codemeta.json","zenodo":null}},"created_at":"2020-11-06T19:34:38.000Z","updated_at":"2025-03-18T21:10:43.000Z","dependencies_parsed_at":"2023-02-05T13:46:31.238Z","dependency_job_id":"fbe252e9-9f5b-4282-8bb3-e648b5c2fb66","html_url":"https://github.com/rOpenSpain/mapSpain","commit_stats":{"total_commits":615,"total_committers":8,"mean_commits":76.875,"dds":0.1447154471544716,"last_synced_commit":"7faf20169c267656d5068929974a448aaa5f7251"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rOpenSpain%2FmapSpain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rOpenSpain%2FmapSpain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rOpenSpain%2FmapSpain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rOpenSpain%2FmapSpain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rOpenSpain","download_url":"https://codeload.github.com/rOpenSpain/mapSpain/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249125958,"owners_count":21216705,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["administrative-boundaries","ccaa","cran","ggplot2","gis","gisco","ign","maps","municipalities","provinces","r","r-package","ropenspain","rstats","spain","spatial","static-tiles","tiles"],"created_at":"2024-11-09T01:18:06.250Z","updated_at":"2025-04-15T18:03:25.969Z","avatar_url":"https://github.com/rOpenSpain.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\nalways_allow_html: true\neditor_options: \n  markdown: \n    wrap: 80\n---\n\n```{r, include = FALSE}\nknitr::opts_knit$set(\n  progress = TRUE,\n  base.url = \"https://raw.githubusercontent.com/ropenspain/mapSpain/main/\"\n)\n\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  tidy = \"styler\",\n  comment = \"#\u003e\",\n  fig.path = \"img/README-\",\n  warning = FALSE,\n  message = FALSE,\n  dev = \"ragg_png\",\n  dpi = 300,\n  out.width = \"100%\"\n)\n\ninitcach \u003c- mapSpain::esp_detect_cache_dir()\nmapSpain::esp_set_cache_dir(\"img/\", verbose = FALSE)\n```\n\n# mapSpain \u003cimg src=\"man/figures/logo.png\" align=\"right\" width=\"120\"/\u003e\n\n\u003c!-- badges: start --\u003e\n\n[![rOS-badge](https://ropenspain.github.io/rostemplate/reference/figures/ropenspain-badge.svg)](https://ropenspain.es/)\n[![CRAN-status](https://www.r-pkg.org/badges/version/mapSpain)](https://CRAN.R-project.org/package=mapSpain)\n[![CRAN-results](https://badges.cranchecks.info/worst/mapSpain.svg)](https://cran.r-project.org/web/checks/check_results_mapSpain.html)\n[![Downloads](https://cranlogs.r-pkg.org/badges/mapSpain)](https://CRAN.R-project.org/package=mapSpain)\n[![r-universe](https://ropenspain.r-universe.dev/badges/mapSpain)](https://ropenspain.r-universe.dev/mapSpain)\n[![R-CMD-check](https://github.com/rOpenSpain/mapSpain/actions/workflows/check-full.yaml/badge.svg)](https://github.com/rOpenSpain/mapSpain/actions/workflows/check-full.yaml)\n[![R-hub](https://github.com/rOpenSpain/mapSpain/actions/workflows/rhub.yaml/badge.svg)](https://github.com/rOpenSpain/mapSpain/actions/workflows/rhub.yaml)\n[![codecov](https://codecov.io/gh/rOpenSpain/mapSpain/branch/main/graph/badge.svg?token=6L01BKLL85)](https://app.codecov.io/gh/rOpenSpain/mapSpain)\n[![DOI](https://img.shields.io/badge/DOI-10.5281/zenodo.5366622-blue)](https://doi.org/10.5281/zenodo.5366622)\n[![Project-Status:Active](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n[![status](https://tinyverse.netlify.app/badge/mapSpain)](https://CRAN.R-project.org/package=mapSpain)\n\n\u003c!-- badges: end --\u003e\n\n[**mapSpain**](https://ropenspain.github.io/mapSpain/) is a package that\nprovides spatial **sf** objects of the administrative boundaries of Spain,\nincluding CCAA, provinces and municipalities.\n\n**mapSpain** also provides a leaflet plugin to be used with the [**leaflet**\npackage](https://rstudio.github.io/leaflet/), that loads several base maps of\npublic institutions of Spain, and the ability of downloading and processing\nstatic tiles.\n\nFull site with examples and vignettes on\n\u003chttps://ropenspain.github.io/mapSpain/\u003e\n\n## Installation\n\nInstall **mapSpain** from\n[**CRAN**](https://CRAN.R-project.org/package=mapSpain):\n\n```{r, eval = FALSE}\ninstall.packages(\"mapSpain\", dependencies = TRUE)\n```\n\nYou can install the developing version of **mapSpain** using the\n[r-universe](https://ropenspain.r-universe.dev/mapSpain):\n\n```{r, eval = FALSE}\n# Install mapSpain in R:\ninstall.packages(\"mapSpain\",\n  repos = c(\n    \"https://ropenspain.r-universe.dev\",\n    \"https://cloud.r-project.org\"\n  ),\n  dependencies = TRUE\n)\n```\n\nAlternatively, you can install the developing version of **mapSpain** with:\n\n```{r, eval = FALSE}\n# install.packages(\"pak\")\npak::pak(\"rOpenSpain/mapSpain\", dependencies = TRUE)\n```\n\n## Usage\n\nThis script highlights some features of **mapSpain** :\n\n```{r static}\nlibrary(mapSpain)\nlibrary(sf)\nlibrary(dplyr)\ncensus \u003c- mapSpain::pobmun19\n\n# Extract CCAA from base dataset\n\ncodelist \u003c- mapSpain::esp_codelist %\u003e%\n  select(cpro, codauto) %\u003e%\n  distinct()\n\ncensus_ccaa \u003c- census %\u003e%\n  left_join(codelist) %\u003e%\n  # Summarize by CCAA\n  group_by(codauto) %\u003e%\n  summarise(pob19 = sum(pob19), men = sum(men), women = sum(women)) %\u003e%\n  mutate(\n    porc_women = women / pob19,\n    porc_women_lab = paste0(round(100 * porc_women, 2), \"%\")\n  )\n\n\n# Merge into spatial data\n\nccaa_sf \u003c- esp_get_ccaa() %\u003e%\n  left_join(census_ccaa)\ncan \u003c- esp_get_can_box()\n\n\n# Plot with ggplot\nlibrary(ggplot2)\n\n\nggplot(ccaa_sf) +\n  geom_sf(aes(fill = porc_women), color = \"grey70\", linewidth = .3) +\n  geom_sf(data = can, color = \"grey70\") +\n  geom_sf_label(aes(label = porc_women_lab),\n    fill = \"white\", alpha = 0.5,\n    size = 3, label.size = 0\n  ) +\n  scale_fill_gradientn(\n    colors = hcl.colors(10, \"Blues\", rev = TRUE),\n    n.breaks = 10, labels = scales::label_percent(),\n    guide = guide_legend(title = \"Porc. women\", position = \"inside\")\n  ) +\n  theme_void() +\n  theme(legend.position.inside = c(0.1, 0.6))\n```\n\nYou can combine `sf` objects with static tiles\n\n```{r tile}\n# Get census\ncensus \u003c- mapSpain::pobmun19 %\u003e%\n  mutate(porc_women = women / pob19) %\u003e%\n  select(cpro, cmun, porc_women)\n\n# Get shapes\nshape \u003c- esp_get_munic_siane(region = \"Segovia\", epsg = 3857)\nprovs \u003c- esp_get_prov_siane(epsg = 3857)\n\nshape_pop \u003c- shape %\u003e% left_join(census)\n\n\ntile \u003c- esp_getTiles(shape_pop, type = \"IDErioja.Relieve\", zoommin = 1)\n\n# Plot\n\nlibrary(ggplot2)\nlibrary(tidyterra)\n\nlims \u003c- as.vector(terra::ext(tile))\n\nggplot(remove_missing(shape_pop, na.rm = TRUE)) +\n  geom_spatraster_rgb(data = tile, maxcell = 10e6) +\n  geom_sf(aes(fill = porc_women), color = NA) +\n  geom_sf(data = provs, fill = NA) +\n  scale_fill_gradientn(\n    colours = hcl.colors(10, \"RdYlBu\", alpha = .5),\n    n.breaks = 8,\n    labels = function(x) {\n      sprintf(\"%1.0f%%\", 100 * x)\n    },\n    guide = guide_legend(title = \"\", )\n  ) +\n  coord_sf(\n    xlim = lims[c(1, 2)],\n    ylim = lims[c(3, 4)],\n    expand = FALSE\n  ) +\n  labs(\n    title = \"Share of women in Segovia by town (2019)\",\n    caption = \"Source: INE, CC BY 4.0 www.iderioja.org\"\n  ) +\n  theme_void() +\n  theme(\n    title = element_text(face = \"bold\")\n  )\n```\n\n## mapSpain and giscoR\n\nIf you need to plot Spain along with another countries, consider using\n[**giscoR**](https://ropengov.github.io/giscoR/) package, that is installed as a\ndependency when you installed **mapSpain**. A basic example:\n\n```{r giscoR, fig.asp=1}\nlibrary(giscoR)\n\n# Set the same resolution for a perfect fit\n\nres \u003c- \"20\"\n\nall_countries \u003c- gisco_get_countries(resolution = res) %\u003e%\n  st_transform(3035)\n\neu_countries \u003c- gisco_get_countries(resolution = res, region = \"EU\") %\u003e%\n  st_transform(3035)\n\nccaa \u003c- esp_get_ccaa(moveCAN = FALSE, resolution = res) %\u003e%\n  st_transform(3035)\n\nlibrary(ggplot2)\n\nggplot(all_countries) +\n  geom_sf(fill = \"#DFDFDF\", color = \"#656565\") +\n  geom_sf(data = eu_countries, fill = \"#FDFBEA\", color = \"#656565\") +\n  geom_sf(data = ccaa, fill = \"#C12838\", color = \"grey80\", linewidth = .1) +\n  # Center in Europe: EPSG 3035\n  coord_sf(xlim = c(2377294, 7453440), ylim = c(1313597, 5628510)) +\n  theme(\n    panel.background = element_blank(),\n    panel.grid = element_line(colour = \"#DFDFDF\", linetype = \"dotted\")\n  )\n```\n\n## A note on caching\n\nSome data sets and tiles may have a size larger than 50MB. You can use\n**mapSpain** to create your own local repository at a given local directory\npassing the following option:\n\n```{r, eval = FALSE}\nesp_set_cache_dir(\"./path/to/location\")\n```\n\nWhen this option is set, **mapSpain** would look for the cached file and it will\nload it, speeding up the process.\n\n## Plotting `sf` objects\n\nSome packages recommended for visualization are:\n\n-   [**tmap**](https://github.com/r-tmap/tmap)\n-   [**mapsf**](https://riatelab.github.io/mapsf/)\n-   [**ggplot2**](https://github.com/tidyverse/ggplot2) +\n    [**tidyterra**](https://github.com/dieghernan/tidyterra).\n-   [**leaflet**](https://rstudio.github.io/leaflet/)\n\n## Citation\n\n```{r echo=FALSE, results='asis'}\nprint(citation(\"mapSpain\"), style = \"html\")\n```\n\nA BibTeX entry for LaTeX users is:\n\n```{r echo=FALSE, comment=''}\ntoBibtex(citation(\"mapSpain\"))\n```\n\n## Contribute\n\nCheck the GitHub page for [source\ncode](https://github.com/ropenspain/mapSpain/).\n\n## Copyright notice\n\nThis package uses data from CartoBase SIANE, provided by Instituto Geográfico\nNacional:\n\n\u003e Atlas Nacional de España (ANE) [CC BY\n\u003e 4.0](https://creativecommons.org/licenses/by/4.0/deed.en)\n\u003e [ign.es](https://www.ign.es/)\n\nSee \u003chttps://github.com/rOpenSpain/mapSpain/tree/sianedata\u003e\n\nThis package uses data from **GISCO**. GISCO\n[(FAQ)](https://ec.europa.eu/eurostat/web/gisco) is a geospatial open data\nrepository including several data sets at several resolution levels.\n\n*From GISCO \\\u003e Geodata \\\u003e Reference data \\\u003e Administrative Units / Statistical\nUnits*\n\n\u003e When data downloaded from this page is used in any printed or electronic\n\u003e publication, in addition to any other provisions applicable to the whole\n\u003e Eurostat website, data source will have to be acknowledged in the legend of\n\u003e the map and in the introductory page of the publication with the following\n\u003e copyright notice:\n\u003e\n\u003e EN: © EuroGeographics for the administrative boundaries\n\u003e\n\u003e FR: © EuroGeographics pour les limites administratives\n\u003e\n\u003e DE: © EuroGeographics bezüglich der Verwaltungsgrenzen\n\u003e\n\u003e For publications in languages other than English, French or German, the\n\u003e translation of the copyright notice in the language of the publication shall\n\u003e be used.\n\nIf you intend to use the data commercially, please contact EuroGeographics for\ninformation regarding their license agreements.\n\n```{r include=FALSE}\nmapSpain::esp_set_cache_dir(initcach, verbose = FALSE)\n```\n\n## Contributors\n\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\nAll contributions to this project are gratefully acknowledged using the [`allcontributors` package](https://github.com/ropensci/allcontributors) following the [allcontributors](https://allcontributors.org) specification. Contributions of any kind are welcome!\n\n### Code\n\n\u003ctable class=\"table allctb-table\" \u003e\n\n\u003ctr\u003e\n\u003ctd align=\"center\"\u003e\n\u003ca href=\"https://github.com/dieghernan\"\u003e\n\u003cimg src=\"https://avatars.githubusercontent.com/u/25656809?v=4\" width=\"100px;\" class=\"allctb-avatar\" alt=\"\"/\u003e\n\u003c/a\u003e\u003cbr\u003e\n\u003ca href=\"https://github.com/rOpenSpain/mapSpain/commits?author=dieghernan\"\u003edieghernan\u003c/a\u003e\n\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003c/table\u003e\n\n\n### Issue Authors\n\n\u003ctable class=\"table allctb-table\" \u003e\n\n\u003ctr\u003e\n\u003ctd align=\"center\"\u003e\n\u003ca href=\"https://github.com/pedrotercero3\"\u003e\n\u003cimg src=\"https://avatars.githubusercontent.com/u/90156958?v=4\" width=\"100px;\" class=\"allctb-avatar\" alt=\"\"/\u003e\n\u003c/a\u003e\u003cbr\u003e\n\u003ca href=\"https://github.com/rOpenSpain/mapSpain/issues?q=is%3Aissue+author%3Apedrotercero3\"\u003epedrotercero3\u003c/a\u003e\n\u003c/td\u003e\n\u003ctd align=\"center\"\u003e\n\u003ca href=\"https://github.com/ajcanepa\"\u003e\n\u003cimg src=\"https://avatars.githubusercontent.com/u/10628672?u=f474ccb4da200b642706382fa2a7e946454af9ab\u0026v=4\" width=\"100px;\" class=\"allctb-avatar\" alt=\"\"/\u003e\n\u003c/a\u003e\u003cbr\u003e\n\u003ca href=\"https://github.com/rOpenSpain/mapSpain/issues?q=is%3Aissue+author%3Aajcanepa\"\u003eajcanepa\u003c/a\u003e\n\u003c/td\u003e\n\u003ctd align=\"center\"\u003e\n\u003ca href=\"https://github.com/fgoerlich\"\u003e\n\u003cimg src=\"https://avatars.githubusercontent.com/u/6486324?v=4\" width=\"100px;\" class=\"allctb-avatar\" alt=\"\"/\u003e\n\u003c/a\u003e\u003cbr\u003e\n\u003ca href=\"https://github.com/rOpenSpain/mapSpain/issues?q=is%3Aissue+author%3Afgoerlich\"\u003efgoerlich\u003c/a\u003e\n\u003c/td\u003e\n\u003ctd align=\"center\"\u003e\n\u003ca href=\"https://github.com/perezcalderon\"\u003e\n\u003cimg src=\"https://avatars.githubusercontent.com/u/8152544?v=4\" width=\"100px;\" class=\"allctb-avatar\" alt=\"\"/\u003e\n\u003c/a\u003e\u003cbr\u003e\n\u003ca href=\"https://github.com/rOpenSpain/mapSpain/issues?q=is%3Aissue+author%3Aperezcalderon\"\u003eperezcalderon\u003c/a\u003e\n\u003c/td\u003e\n\u003ctd align=\"center\"\u003e\n\u003ca href=\"https://github.com/Cidree\"\u003e\n\u003cimg src=\"https://avatars.githubusercontent.com/u/96820235?u=473cfd139b57545c3f9fc8ddb070ac1909db7b22\u0026v=4\" width=\"100px;\" class=\"allctb-avatar\" alt=\"\"/\u003e\n\u003c/a\u003e\u003cbr\u003e\n\u003ca href=\"https://github.com/rOpenSpain/mapSpain/issues?q=is%3Aissue+author%3ACidree\"\u003eCidree\u003c/a\u003e\n\u003c/td\u003e\n\u003ctd align=\"center\"\u003e\n\u003ca href=\"https://github.com/catbru\"\u003e\n\u003cimg src=\"https://avatars.githubusercontent.com/u/2419189?u=d8fd560c3e349236450bdd9669f9d2ef1176d8d9\u0026v=4\" width=\"100px;\" class=\"allctb-avatar\" alt=\"\"/\u003e\n\u003c/a\u003e\u003cbr\u003e\n\u003ca href=\"https://github.com/rOpenSpain/mapSpain/issues?q=is%3Aissue+author%3Acatbru\"\u003ecatbru\u003c/a\u003e\n\u003c/td\u003e\n\u003ctd align=\"center\"\u003e\n\u003ca href=\"https://github.com/ana-m-m\"\u003e\n\u003cimg src=\"https://avatars.githubusercontent.com/u/78867570?u=e82579f7b35ca989a167342ad18e5c003980943a\u0026v=4\" width=\"100px;\" class=\"allctb-avatar\" alt=\"\"/\u003e\n\u003c/a\u003e\u003cbr\u003e\n\u003ca href=\"https://github.com/rOpenSpain/mapSpain/issues?q=is%3Aissue+author%3Aana-m-m\"\u003eana-m-m\u003c/a\u003e\n\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003c/table\u003e\n\n\n### Issue Contributors\n\n\u003ctable class=\"table allctb-table\" \u003e\n\n\u003ctr\u003e\n\u003ctd align=\"center\"\u003e\n\u003ca href=\"https://github.com/mpizarrotig\"\u003e\n\u003cimg src=\"https://avatars.githubusercontent.com/u/18368413?u=a85f35a53cf336f532b6e939b68ebf430669d2f5\u0026v=4\" width=\"100px;\" class=\"allctb-avatar\" alt=\"\"/\u003e\n\u003c/a\u003e\u003cbr\u003e\n\u003ca href=\"https://github.com/rOpenSpain/mapSpain/issues?q=is%3Aissue+commenter%3Ampizarrotig\"\u003empizarrotig\u003c/a\u003e\n\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003c/table\u003e\n\n\u003c!-- markdownlint-enable --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropenspain%2Fmapspain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fropenspain%2Fmapspain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropenspain%2Fmapspain/lists"}