Este cuaderno visualiza la abstención por provincias de las elecciones del 28M 2023

Cargar librerías

library(tidyverse)
library(ggrepel)   # para etiquetas
library(RColorBrewer)
library(mapSpain)
library(sf)
library(ggthemes)    # Temas
locale(date_names = "es", date_format = "%AD", time_format = "%AT",
  decimal_mark = ",", grouping_mark = ".", tz = "Europe/Berlin",
  encoding = "UTF-8", asciify = FALSE)
## <locale>
## Numbers:  123.456,78
## Formats:  %AD / %AT
## Timezone: Europe/Berlin
## Encoding: UTF-8
## <date_names>
## Days:   domingo (dom.), lunes (lun.), martes (mar.), miércoles (mié.), jueves
##         (jue.), viernes (vie.), sábado (sáb.)
## Months: enero (ene.), febrero (feb.), marzo (mar.), abril (abr.), mayo (may.),
##         junio (jun.), julio (jul.), agosto (ago.), septiembre (sept.),
##         octubre (oct.), noviembre (nov.), diciembre (dic.)
## AM/PM:  a. m./p. m.
Sys.setlocale(category = "LC_ALL", locale = "spanish")
## [1] "LC_COLLATE=Spanish_Spain.1252;LC_CTYPE=Spanish_Spain.1252;LC_MONETARY=Spanish_Spain.1252;LC_NUMERIC=C;LC_TIME=Spanish_Spain.1252"

Leer datos

participacion_datos = "https://raw.githubusercontent.com/congosto/congosto.github.io/master/28M_participacion.csv"
participacion_df <- read_delim (
  participacion_datos, delim = ";") %>%
  mutate (porcentaje_participacion = as.numeric(sub(",", ".", porcentaje_participacion, fixed = TRUE))) %>%
  mutate (abstencion = 100 - porcentaje_participacion) %>%
  mutate(color_text = ifelse(abstencion > 36.08, "alta","baja"))

Participación por provincia

mapSpain_prov <- esp_get_prov()
map_provincias_abstencion <-left_join (mapSpain_prov,participacion_df, by = c("ine.prov.name"="provincia_INE" ))
breaks <- c(seq(20,50, by = 10))
Can <- esp_get_can_box()
ggplot(data =map_provincias_abstencion ) +
  geom_sf(
    aes(
      fill = abstencion),
      color = "grey80") + 
  geom_sf(data = Can, color = "grey70") +
  geom_sf_label (
    aes(label = round(abstencion,1),
        fill = abstencion,
        color = color_text),
    stat = "sf_coordinates",
    size = 2.5,
    label.padding = unit(0.12, "lines"),
    label.size = 0,
    ) +
  scale_fill_gradient (
    low = "#D6D2D2",high = "#7A7878",
    aesthetics = "fill" ) +
  scale_colour_manual('', values = c('alta'='#D6D2D2', 'baja'='grey40')) +
  labs(
    title = "Elecciones 28M 2023: Porcentaje de abstención  por provincia",
    subtitle = "Abstención global 36,08%.\nLas provincias con los porcentajes en color blanco están por encima de la abstención global",
    x = "",
    y = "",
    fill = "% Abstención",
    caption = "by @congosto\nFuentes: https://resultados.locales2023.es/\nhttps://elecciones.eldiario.es/") +
  guides(fill = guide_colourbar(nbin = 5)) +
  guides(color = "none") +
  theme_void() +
  theme (
    legend.position = c(0.1, 0.6),
    title = element_text(color  = "grey50", size = 12),
    plot.subtitle = element_text(color  = "grey50", size = 10),
    legend.text =  element_text(color  = "grey50", size = 8))