{"id":50646166,"url":"https://github.com/rOpenSpain/Siane","last_synced_at":"2026-06-24T09:00:57.596Z","repository":{"id":55535049,"uuid":"91350495","full_name":"rOpenSpain/Siane","owner":"rOpenSpain","description":"R package to represent statistical data on official Spanish maps at several administrative levels","archived":false,"fork":false,"pushed_at":"2021-07-26T11:37:37.000Z","size":23331,"stargazers_count":10,"open_issues_count":6,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-06-11T21:28:15.622Z","etag":null,"topics":["choropleth","choropleth-map","ign","ine","maps","spain"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rOpenSpain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-15T14:57:34.000Z","updated_at":"2022-11-30T16:41:07.000Z","dependencies_parsed_at":"2022-08-15T02:40:56.653Z","dependency_job_id":null,"html_url":"https://github.com/rOpenSpain/Siane","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rOpenSpain/Siane","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rOpenSpain%2FSiane","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rOpenSpain%2FSiane/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rOpenSpain%2FSiane/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rOpenSpain%2FSiane/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rOpenSpain","download_url":"https://codeload.github.com/rOpenSpain/Siane/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rOpenSpain%2FSiane/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34724743,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-24T02:00:07.484Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["choropleth","choropleth-map","ign","ine","maps","spain"],"created_at":"2026-06-07T13:00:29.297Z","updated_at":"2026-06-24T09:00:57.590Z","avatar_url":"https://github.com/rOpenSpain.png","language":"R","funding_links":[],"categories":["Datos Abiertos y Estadísticas"],"sub_categories":["Región de Murcia"],"readme":"# Siane\n\nThis is an R package to plot maps based on [CartoSiane](http://www.ign.es/web/resources/docs/IGNCnig/ANE-SIANE.pdf), the official Spanis maps provided by the [Instituto Geográfico Nacional](http://www.ign.es) (IGN). These maps are compatible with the Spanish [Instituto Nacional de Estadística](http://www.ine.es/) (INE) georreferenced data; this makes it simple to combine geographical and statistical data to produce maps.\n\nThis document explains how to install the package, how to download the base maps, and, finally, how to produce a number of simple statistical maps.\n\n\n## Package installation\n\nTo install the package, you need to download Siane maps first.\n\n### Obtain Siane maps\n\nThe package does not include the map layers. These need to be downloaded from the IGN first from [this website](http://centrodedescargas.cnig.es/CentroDescargas/catalogo.do?Serie=CAANE#selectedSerie).\n\nYou need to scroll down to the bottom of the page and click in the highlighted button:\n\n![Image](https://raw.githubusercontent.com/rOpenSpain/Siane/master/Images/image_1.png)  \n\nYou will get into in a new page where you will have to click on __\"Buscar por polígono\"__\n\n![Image](https://raw.githubusercontent.com/rOpenSpain/Siane/master/Images/image_2.png)  \n\nOnce you get here, draw a triangle in the surface of the map. It just has to be a closed polygon. A simple triangle will do it.\nThen, you need to unlist all the products by clicking on the \"+\" button.  \n\n![Image](https://raw.githubusercontent.com/rOpenSpain/Siane/master/Images/image_4.png)  \n\nYou will need to download the `SIANE_CARTO_BASE_S_3M` and `SIANE_CARTO_BASE_S_6M5` maps.\n\n![Image](https://raw.githubusercontent.com/rOpenSpain/Siane/master/Images/image_5.png)    \n\nYou need to unzip the folders in the same directory. `Siane` should have access to both folders in order to plot the maps. For instance, my folders (`SIANE_CARTO_BASE_S_3M` and `SIANE_CARTO_BASE_S_6M5`) are stored at `/Users/nunoc/Desktop/siane`. You shouldnt' rename neither the files nor the directories.\n\n\n### Install the package\n\nTo install, the package, all you need to do is:\n\n```\nlibrary(devtools)\ninstall_github(\"rOpenSpain/Siane\")\nlibrary(Siane)\n```\n\nThen you can use it in your session:\n\n```\nlibrary(Siane)\n```\n\nHowever, the package is not usable until you _register_ the maps, i.e., you indicate where to find them.\n\n### Register and test the package\n\nTo register the maps, you need to indicate the full path to the directory storing the `SIANE_CARTO_BASE_S_3M` and `SIANE_CARTO_BASE_S_6M5` folders. In my case:\n\n```\nobj \u003c- register_siane(\"/Users/Nuniemsis/Desktop/siane/\")\n```\n\nThen you can select the map,\n\n```\nshp \u003c- siane_map(obj = obj, level = \"Municipios\", canarias = TRUE, peninsula = \"close\")\n```\n\nand plot it:\n\n```\nraster::plot(shp)\n```\n\n## Map options\n\nThis section describes some of the parameters to select the map features.\n\n  - `year`: Maps change over time and Siane keeps a historic version of them. You can select the year corresponding to the base map. This is particularly useful for municipalities.\n  - `canarias`: It indicates whether we want to plot the Canary islands.  \n  - `level`: It is the administrative level. For this set of maps there are three: `Municipios`, `Provincias` and `Comunidades`.  \n  - `scale`: The scale of the maps. The default scale for municipalities is 1:3000000  `scale = \"3m\" `. For provinces and regions the default scale is 1:6500000 `scale = \"6m\"`.  \n  - `peninsula`: It's the relative position of the Canarias island to the peninsula in case you want it to be shifted closer to it.\n\n```\nshp \u003c- siane_map(obj, level = \"Municipios\", canarias = TRUE, peninsula = \"close\")\nplot(shp)\n```\n\n## Plotting INE data\n\nOne of the advantages of Siane maps is that their entities are indexed using official INE codes. This facilitates the creation of maps representing statistical variables. This section illustrates the procedure. In particular, we will plot the population of the municipalities of [__La Rioja__](http://www.ine.es/jaxiT3/Tabla.htm?t=2879).   \n\n### Data download\n\nTo download the data from the INE, you need to click on the button on the right side of the webpage and choose the Pc-Axis format.\n\n![Image](https://raw.githubusercontent.com/rOpenSpain/Siane/master/Images/image_6.PNG)  \n\nYou will need the `pxR` package to read this file.\n\n```\nlibrary(pxR)\nlibrary(RColorBrewer)\n\nine_path \u003c- \"/Users/nunoc/Downloads/2879.px\"\ndf \u003c- as.data.frame(read.px(ine_path))\n\nnames(df) # List the column names  of the data frame\n```\n\nOf course, you will have to provide the path where you have downloaded the `2879.px` file.\n\n### Data preparation\n\nFirst we need to understand the data frame. It has the following columns:\n\n- `Periodo` is the time column in year's format.  \n- `value` is a column with the numeric value of the population.  \n- `Sexo` is the sex of that population.  \n- `Municipios` is a character array with the municipality name and the municipality code\n\nIn this dataset there is only one value per territory.  \n\nSplit the `Municipios` column to get the municipality's codes. We are storing the codes in the column `codes`. This column is really important in order to plot the polygons with the correct colours.\n\nWe create a single column in the data frame with those codes.\n```\ndf$codes \u003c- sapply(df$Municipios, function(x) strsplit(as.character(x), split = \" \")[[1]][1])\ndf$Periodo \u003c- as.numeric(as.character(df$Periodo))\n```\n\nPlotting polygons by colour intensity requires one unique value per territory. Therefore, we have to filter the data frame. Keep this __Golden rule__: One value per territory. In this example I want to plot the total population in the year 2016.   \n\n```\ndf \u003c- df[df$Sex == \"Total\" \u0026 df$Periodo == 2016, ]\n```\n\nNext, we need to include our population data into the map object, `shp`\n\n\n```\nby \u003c- \"codes\"\nvalue \u003c- \"value\"\nlevel \u003c- \"Municipios\"\n\nshp_merged \u003c- siane_merge(shp = shp, df = df, by = by, level = level, value = value)\n```\n\nThen, we can plot the map with the `plot` function. The `RColorBrewer` package provides lots of colour scales. We can use this colour scales to visualize data over the map. The following function displays all the colour scales from that package. In case we want to plot the population of certain municipalities in a province, we must use a sequential pallete.\n\n```\npallete_colour \u003c- \"OrRd\" # Scale of oranges and reds\n```\n\nLet's say that `n` is the number of colour intervals.\n\n```\nn \u003c- 5\n```\n\nThe brewer.pal function builds a pallete with `n` intervals and the `pallete_colour` colour.\n```\nvalues_ine \u003c- shp_merged@data[[value]] # Values we want to plot are stored in the shape@data data frame\ncolors \u003c- brewer.pal(n, pallete_colour) # A pallete from RColorBrewer\n\n```\n\nThe style is the distribution of colour within a numerical range. The `classIntervals` function generates numerical intervals. The upper and lower limits of these intervals are named breaks.\n\n```\nstyle \u003c- \"quantile\"\nbrks \u003c- classIntervals(values_ine, n = n, style = style)\nmy_pallete \u003c- brks$brks # my_pallete is a vector of breaks\n```\n\nMatch each number with its corresponding interval to be able to decide its colour.\n```\ncol \u003c- colors[findInterval(values_ine, my_pallete,\n                           all.inside=TRUE)] # Setting the final colors\n```\n\nPlot the map and set title and legends.\n\n```\nraster::plot(shp_merged,col = col) # Plot the map\ntitle_plot \u003c- \"Población total por municipios en La Rioja\"\n\ntitle(main = title_plot)\nlegend(legend = leglabs(round(my_pallete)), fill = colors,x = \"bottomright\")\n```\n\nThe resulting map is:\n\n![Image](https://raw.githubusercontent.com/rOpenSpain/Siane/master/Images/image_7.png)\n\n\n### Other examples\n\nLet's try with a different [dataset](http://www.ine.es/jaxiT3/Tabla.htm?t=2852\u0026L=0). This dataset has the spanish population for all the provinces.You can find the link in the README.MD file as well. Now we are going to go deeper in some options.\n\n```\nine_path \u003c- \"/Users/nunoc/Downloads/2852.px\"\ndf \u003c- as.data.frame(read.px(ine_path))\nnames(df) # List the column names  of the data frame\n```\n\n\n#### Data preparation\n\nThe same steps as before.\n\n```\ndf[[by]] \u003c- sapply(df$Provincias,\n                   function(x) strsplit(x = as.character(x), split = \" \")[[1]][1])\n```\n\n```\ndf$Periodo \u003c- as.numeric(as.character(df$Periodo))\n```\n\n```\n\nyear \u003c- 2016 # year of the maps\n\ndf \u003c- df[df$Sex == \"Total\" \u0026 df$Periodo == year,]\n```\n\nThe options now will be slightly different:`level \u003c- \"Provincias\"`. Remember that first we have to create the shapefile. We can't use the previous shapefile provided that the level has changed. These maps are provincial maps.\n\n```\nlevel \u003c- \"Provincias\"\ncanarias \u003c- FALSE\nscale \u003c- \"6m\" # \"3m\" also accepted\n```\n\n#### Read the map\n\n```\nshp \u003c- siane_map(obj = obj, canarias = canarias, year = year, level = level, scale = scale)\n```\n\n###### Map options\n\nThe values are in the `values` column and the codes are in the `codes` column.\n\n```\nvalue \u003c- \"value\"\nby \u003c- \"codes\"\n```\n\n\n```\n\nshp_merged \u003c- siane_merge(shp = shp, df = df, by = by, value = value)\n```\n\n\n#### Plot the map.\n\n\n```{r, fig.width = 7, fig.height = 7, eval = FALSE}\npallete_colour \u003c- \"BuPu\"\nn \u003c- 7\nstyle \u003c- \"kmeans\"\n\nvalues_ine \u003c- shp_merged@data[[value]] # Values we want to plot are stored in the shape@data data frame\ncolors \u003c- brewer.pal(n, pallete_colour) # A pallete from RColorBrewer\n\nbrks \u003c- classIntervals(values_ine, n = n, style = style)\nmy_pallete \u003c- brks$brks\n\ncol \u003c- colors[findInterval(values_ine, my_pallete,\n                           all.inside=TRUE)] # Setting the final colors\n\nraster::plot(shp_merged,col = col) # Plot the map\n\ntitle_plot \u003c- \"Población de España a nivel de provincias\"\n\ntitle(main = title_plot)\nlegend(legend = leglabs(round(my_pallete)), fill = colors,x = \"bottomright\")\n```\n\nThis produces the map:\n\n![Image](https://raw.githubusercontent.com/rOpenSpain/Siane/master/Images/image_8.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FrOpenSpain%2FSiane","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FrOpenSpain%2FSiane","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FrOpenSpain%2FSiane/lists"}