The goal of infoelectoral is to facilitate the downloading and necessary processing of official data on electoral results from the Ministry of the Interior of Spain. Files can be downloaded at the polling station and municipality level on the ministry’s website. However, the format of the files (plain text without delimitation) and the data structure design (the useful information for the analysis of the elections is dispersed in at least three different files) make importing the data somewhat costly.
To download the data at the municipality level, you have the
municipalities ()
function to which you have to provide the
type of desired election (“congreso”, “senado”, “municipales” or
“europeas”, the Ministry of the Interior does not have the data from the
regional electoral processes), the year (YYYY) and the month (MM) of the
election.
library(infoelectoral)
library(dplyr)
df <- municipios(tipo_eleccion = "congreso", anno = "1982", mes = "10")
glimpse(df)
## Rows: 119,188
## Columns: 34
## $ tipo_eleccion <chr> "02", "02", "02", "02", "02", "02", "02", "0…
## $ anno <chr> "1982", "1982", "1982", "1982", "1982", "198…
## $ mes <chr> "10", "10", "10", "10", "10", "10", "10", "1…
## $ vuelta <chr> "1", "1", "1", "1", "1", "1", "1", "1", "1",…
## $ codigo_ccaa <chr> "01", "01", "01", "01", "01", "01", "01", "0…
## $ codigo_provincia <chr> "04", "04", "04", "04", "04", "04", "04", "0…
## $ codigo_municipio <chr> "001", "001", "001", "001", "001", "001", "0…
## $ municipio <chr> "Abla", "Abla", "Abla", "Abla", "Abla", "Abl…
## $ codigo_distrito <chr> "99", "99", "99", "99", "99", "99", "99", "9…
## $ codigo_distrito_electoral <chr> "0", "0", "0", "0", "0", "0", "0", "0", "0",…
## $ codigo_partido_judicial <chr> "013", "013", "013", "013", "013", "013", "0…
## $ codigo_diputacion <chr> "013", "013", "013", "013", "013", "013", "0…
## $ codigo_comarca <chr> "000", "000", "000", "000", "000", "000", "0…
## $ poblacion_derecho <dbl> 1723, 1723, 1723, 1723, 1723, 1723, 1723, 17…
## $ numero_mesas <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
## $ censo_ine <dbl> 1226, 1226, 1226, 1226, 1226, 1226, 1226, 12…
## $ censo_escrutinio <dbl> 1226, 1226, 1226, 1226, 1226, 1226, 1226, 12…
## $ censo_cere <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ votantes_cere <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ participacion_1 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ participacion_2 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ votos_blancos <dbl> 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,…
## $ votos_nulos <dbl> 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,…
## $ votos_candidaturas <dbl> 983, 983, 983, 983, 983, 983, 983, 983, 983,…
## $ numero_concejales <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ codigo_partido_nacional <chr> "000005", "000015", "000019", "000033", "000…
## $ codigo_partido_autonomia <chr> "000005", "000015", "000019", "000033", "000…
## $ codigo_partido_provincia <chr> "000005", "000015", "000019", "000033", "000…
## $ codigo_partido <chr> "000005", "000015", "000019", "000033", "000…
## $ denominacion <chr> "ALIANZA POPULAR - PARTIDO DEMOCRATA POPULAR…
## $ siglas <chr> "AP-PDP", "CDS", "CUC", "FN", "LCR", "MCA", …
## $ votos <dbl> 134, 6, 0, 2, 0, 0, 2, 5, 2, 1, 7, 365, 0, 4…
## $ datos_oficiales <chr> "N", "N", "N", "N", "N", "N", "N", "N", "N",…
## $ concejales_obtenidos <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
To download election data at the polling station level:
df <- mesas("congreso", "2019", "04")
glimpse(df)
## Rows: 712,171
## Columns: 28
## $ tipo_eleccion <chr> "02", "02", "02", "02", "02", "02", "02", "02…
## $ anno <chr> "2019", "2019", "2019", "2019", "2019", "2019…
## $ mes <chr> "04", "04", "04", "04", "04", "04", "04", "04…
## $ vuelta <chr> "1", "1", "1", "1", "1", "1", "1", "1", "1", …
## $ codigo_ccaa <chr> "01", "01", "01", "01", "01", "01", "01", "01…
## $ codigo_provincia <chr> "04", "04", "04", "04", "04", "04", "04", "04…
## $ codigo_municipio <chr> "003", "003", "003", "003", "003", "003", "00…
## $ municipio <chr> "Adra", "Adra", "Adra", "Adra", "Adra", "Adra…
## $ codigo_distrito <chr> "01", "01", "01", "01", "01", "01", "01", "01…
## $ codigo_seccion <chr> "004", "004", "004", "004", "004", "004", "00…
## $ codigo_mesa <chr> "B", "B", "B", "B", "B", "B", "B", "B", "B", …
## $ censo_ine <dbl> 841, 841, 841, 841, 841, 841, 841, 841, 841, …
## $ censo_cera <dbl> 841, 841, 841, 841, 841, 841, 841, 841, 841, …
## $ censo_cere <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ votantes_cere <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ participacion_1 <dbl> 310, 310, 310, 310, 310, 310, 310, 310, 310, …
## $ participacion_2 <dbl> 435, 435, 435, 435, 435, 435, 435, 435, 435, …
## $ votos_blancos <dbl> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, …
## $ votos_nulos <dbl> 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, …
## $ votos_candidaturas <dbl> 547, 547, 547, 547, 547, 547, 547, 547, 547, …
## $ codigo_partido_nacional <chr> "000117", "000028", "000104", "000083", "0000…
## $ codigo_partido_autonomia <chr> "000117", "000028", "000104", "000083", "0000…
## $ codigo_partido_provincia <chr> "000117", "000028", "000104", "000083", "0000…
## $ codigo_partido <chr> "000117", "000028", "000104", "000083", "0000…
## $ denominacion <chr> "VOX", "ESCAÑOS EN BLANCO", "RECORTES CERO-GR…
## $ siglas <chr> "VOX", "EB", "RECORTES CE", "PP", "PSOE", "PO…
## $ votos <dbl> 155, 2, 1, 89, 183, 35, 78, 3, 1, 0, 122, 0, …
## $ datos_oficiales <chr> "S", "S", "S", "S", "S", "S", "S", "S", "S", …
The infoelectoral
library also has the function candidatos()
, which allows
the downloading of data on candidates for the Senate, the Congress of
Deputies, the European Parliament and city councils. In the case of
Senate candidates, the function requires a value in the argument
nivel
indicating whether the results are wanted at the
municipality or polling station level, and the resulting
data.frame
will include a column called votos
indicating the number of ballots received by each candidate for the
Upper House.
df <- candidatos(tipo_eleccion = "senado", anno = "2019", mes = "11", nivel = "municipio")
glimpse(df)
## Rows: 195,543
## Columns: 39
## $ tipo_eleccion <chr> "03", "03", "03", "03", "03", "03", "03", "0…
## $ anno <chr> "2019", "2019", "2019", "2019", "2019", "201…
## $ mes <chr> "11", "11", "11", "11", "11", "11", "11", "1…
## $ vuelta <chr> "1", "1", "1", "1", "1", "1", "1", "1", "1",…
## $ codigo_ccaa <chr> "01", "01", "01", "01", "01", "01", "01", "0…
## $ codigo_provincia <chr> "04", "04", "04", "04", "04", "04", "04", "0…
## $ codigo_distrito_electoral <chr> "0", "0", "0", "0", "0", "0", "0", "0", "0",…
## $ codigo_municipio <chr> "001", "001", "001", "001", "001", "001", "0…
## $ municipio <chr> "Abla", "Abla", "Abla", "Abla", "Abla", "Abl…
## $ codigo_distrito <chr> "99", "99", "99", "99", "99", "99", "99", "9…
## $ numero_mesas <dbl> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,…
## $ poblacion_derecho <dbl> 1235, 1235, 1235, 1235, 1235, 1235, 1235, 12…
## $ censo_ine <dbl> 1002, 1002, 1002, 1002, 1002, 1002, 1002, 10…
## $ censo_escrutinio <dbl> 1002, 1002, 1002, 1002, 1002, 1002, 1002, 10…
## $ censo_cere <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ votantes_cere <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ participacion_1 <dbl> 393, 393, 393, 393, 393, 393, 393, 393, 393,…
## $ participacion_2 <dbl> 588, 588, 588, 588, 588, 588, 588, 588, 588,…
## $ votos_blancos <dbl> 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,…
## $ votos_nulos <dbl> 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, …
## $ votos_candidaturas <dbl> 685, 685, 685, 685, 685, 685, 685, 685, 685,…
## $ codigo_partido_nacional <chr> "000094", "000094", "000094", "000083", "000…
## $ codigo_partido_autonomia <chr> "000094", "000094", "000094", "000083", "000…
## $ codigo_partido_provincia <chr> "000094", "000094", "000094", "000083", "000…
## $ codigo_partido <chr> "000094", "000094", "000094", "000083", "000…
## $ denominacion <chr> "denominacion", "denominacion", "denominacio…
## $ siglas <chr> "PSOE", "PSOE", "PSOE", "PP", "PP", "PP", "C…
## $ codigo_senador <chr> "049001", "049002", "049003", "049004", "049…
## $ orden_candidato <dbl> 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 1, 2, 3, 1, 2,…
## $ tipo_candidato <chr> "T", "T", "T", "T", "T", "T", "T", "T", "T",…
## $ nombre <chr> "Fernando", "Ines María", "Juan Carlos", "Ra…
## $ apellido_1 <chr> "Martínez", "Plaza", "Pérez", "Hernando", "R…
## $ apellido_2 <chr> "López", "García", "Navas", "Fraile", "Pérez…
## $ sexo <chr> "M", "F", "M", "M", "M", "F", "M", "F", "M",…
## $ nacimiento <date> 2024-03-11, 2024-03-11, 2024-03-11, 2024-03…
## $ dni <chr> "0000000000", "0000000000", "0000000000", "0…
## $ votos <dbl> 309, 305, 298, 212, 213, 195, 52, 47, 43, 10…
## $ electo <chr> "S", "S", "N", "S", "S", "N", "N", "N", "N",…
## $ datos_oficiales <chr> "S", "S", "S", "S", "S", "S", "S", "S", "S",…
In the case of candidates for the Congress of Deputies, European
Parliament or city councils, institutions elected through closed lists,
it is not necessary to provide a value for the argument
nivel
and the resulting object will not have the column
votos
.
df <- candidatos("europeas", "2019", "05")
glimpse(df)
## Rows: 1,728
## Columns: 22
## $ tipo_eleccion <chr> "07", "07", "07", "07", "07", "07", "07", "07…
## $ anno <chr> "2019", "2019", "2019", "2019", "2019", "2019…
## $ mes <chr> "05", "05", "05", "05", "05", "05", "05", "05…
## $ vuelta <chr> "1", "1", "1", "1", "1", "1", "1", "1", "1", …
## $ codigo_provincia <chr> "99", "99", "99", "99", "99", "99", "99", "99…
## $ codigo_municipio <chr> "999999", "999999", "999999", "999999", "9999…
## $ codigo_distrito <chr> "99", "99", "99", "99", "99", "99", "99", "99…
## $ orden_candidato <dbl> 8, 9, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,…
## $ tipo_candidato <chr> "T", "T", "T", "T", "T", "T", "T", "T", "T", …
## $ nombre <chr> "Francisco Javier", "Francesca", "María Teres…
## $ apellido_1 <chr> "Cobos", "Ropero", "Ruso", "Pangua", "Jiménez…
## $ apellido_2 <chr> "Núñez", "Ramos", "Bernadó", "de la Varga", "…
## $ sexo <chr> "M", "F", "F", "M", "F", "M", "F", "M", "F", …
## $ nacimiento <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ dni <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ electo <chr> "N", "N", "N", "N", "N", "N", "N", "N", "N", …
## $ codigo_partido_nacional <chr> "000028", "000028", "000013", "000013", "0000…
## $ codigo_partido_autonomia <chr> "000028", "000028", "000013", "000013", "0000…
## $ codigo_partido_provincia <chr> "000028", "000028", "000013", "000013", "0000…
## $ codigo_partido <chr> "000028", "000028", "000013", "000013", "0000…
## $ denominacion <chr> "denominacion", "denominacion", "denominacion…
## $ siglas <chr> "VOLT", "VOLT", "PH", "PH", "PH", "PH", "PH",…