Preparación de datasets
Ronda 2018
lb18 <- lb2018 %>%
select(año, IDENPA, REG, CIUDAD, WT,
contains("P20STGBSC"), # Aprobación presidencial
contains("P15STGBSC.E"), # Confianza en el gobierno
contains("PERPART"), # Partido en el gobierno
contains("FAMPART")) %>% # Familia partidista
mutate (party_id = NA) %>%
rename(
idenpa = IDENPA,
reg = REG,
ciudad = CIUDAD,
wt = WT,
aprobacion_pre = P20STGBSC,
confianza_g = P15STGBSC.E,
perpart = PERPART,
fampart = FAMPART
)
Ronda 2020
lb20<- lb2020 %>%
select(año, idenpa, reg, ciudad, wt,
contains("P17STGBS"), # Aprobación presidencial
contains("P13ST.E"), # Confianza en el gobierno
contains("P49STGBS"), # Cercanía a un partido político
contains("perpart"), # Partido en el gobierno
contains("fampart" )) %>%
rename(
aprobacion_pre = p17stgbs,
confianza_g = p13st.e,
party_id = p49stgbs,
)
Ronda 2023
lb23 <- lb2023 %>%
select(año, idenpa, reg, ciudad, wt,
contains("P15STGBS"), # Aprobación presidencial
contains("P13ST.E"), # Confianza en el gobierno
contains("P42STGBS"), # Cercanía a un partido político
contains("perpart"),
contains("fampart")) %>%
rename (
aprobacion_pre = P15STGBS,
confianza_g = P13ST.E,
party_id = P42STGBS,
) %>% mutate (año = 2023)
Detección de valores perdidos
lb18 <- lb18 %>% mutate (across(everything(),
~ ifelse(. < 0 | . %in% c(95, 96, 97, 98, 99),
NA, . )))
lb20 <- lb20 %>% mutate (across(everything(),
~ ifelse(. < 0 | . %in% c(95, 96, 97, 98, 99),
NA, . )))
lb23 <- lb23 %>% mutate (across(everything(),
~ ifelse(. < 0 | . %in% c(95, 96, 97, 98, 99),
NA, . )))
Exploración de valores perdidos
skim(lb18)
Data summary
| Name |
lb18 |
| Number of rows |
20204 |
| Number of columns |
10 |
| _______________________ |
|
| Column type frequency: |
|
| logical |
1 |
| numeric |
9 |
| ________________________ |
|
| Group variables |
None |
Variable type: logical
Variable type: numeric
| año |
0 |
1.00 |
2018.00 |
0.00 |
2.0180e+03 |
2.01800e+03 |
2018 |
2018 |
2018.0 |
▁▁▇▁▁ |
| idenpa |
0 |
1.00 |
365.38 |
260.49 |
3.2000e+01 |
1.70000e+02 |
222 |
591 |
862.0 |
▇▆▂▅▃ |
| reg |
0 |
1.00 |
365448.91 |
260474.23 |
3.2001e+04 |
1.70006e+05 |
222302 |
591005 |
862033.0 |
▇▆▂▅▃ |
| ciudad |
0 |
1.00 |
365435337.95 |
260481809.33 |
3.2001e+07 |
1.70002e+08 |
222030210 |
591005005 |
862023024.0 |
▇▆▂▅▃ |
| wt |
0 |
1.00 |
1.00 |
0.39 |
4.5000e-01 |
9.80000e-01 |
1 |
1 |
13.1 |
▇▁▁▁▁ |
| aprobacion_pre |
1244 |
0.94 |
1.66 |
0.47 |
1.0000e+00 |
1.00000e+00 |
2 |
2 |
2.0 |
▅▁▁▁▇ |
| confianza_g |
455 |
0.98 |
3.15 |
0.91 |
1.0000e+00 |
3.00000e+00 |
3 |
4 |
4.0 |
▁▃▁▆▇ |
| perpart |
0 |
1.00 |
2.98 |
1.24 |
1.0000e+00 |
2.00000e+00 |
4 |
4 |
4.0 |
▂▃▁▁▇ |
| fampart |
1037 |
0.95 |
17.91 |
24.91 |
0.0000e+00 |
0.00000e+00 |
0 |
40 |
90.0 |
▇▂▂▂▁ |
skim(lb20)
Data summary
| Name |
lb20 |
| Number of rows |
20204 |
| Number of columns |
10 |
| _______________________ |
|
| Column type frequency: |
|
| numeric |
10 |
| ________________________ |
|
| Group variables |
None |
Variable type: numeric
| año |
0 |
1.00 |
2020.00 |
0.00 |
2020.0 |
2020 |
2020 |
2020 |
2.02000e+03 |
▁▁▇▁▁ |
| idenpa |
0 |
1.00 |
365.38 |
260.49 |
32.0 |
170 |
222 |
591 |
8.62000e+02 |
▇▆▂▅▃ |
| reg |
1 |
1.00 |
365447.19 |
260488.31 |
32001.0 |
170006 |
222302 |
591005 |
8.62033e+05 |
▇▆▂▅▃ |
| ciudad |
6 |
1.00 |
365528151.34 |
260461425.54 |
32001001.0 |
170002000 |
222030209 |
591005005 |
8.62023e+08 |
▇▆▂▅▃ |
| wt |
0 |
1.00 |
1.00 |
0.41 |
0.4 |
1 |
1 |
1 |
2.46600e+01 |
▇▁▁▁▁ |
| aprobacion_pre |
1411 |
0.93 |
1.58 |
0.49 |
1.0 |
1 |
2 |
2 |
2.00000e+00 |
▆▁▁▁▇ |
| confianza_g |
456 |
0.98 |
3.03 |
1.00 |
1.0 |
2 |
3 |
4 |
4.00000e+00 |
▂▃▁▆▇ |
| party_id |
568 |
0.97 |
1.69 |
0.46 |
1.0 |
1 |
2 |
2 |
2.00000e+00 |
▃▁▁▁▇ |
| perpart |
0 |
1.00 |
3.05 |
1.26 |
1.0 |
2 |
4 |
4 |
4.00000e+00 |
▂▂▁▁▇ |
| fampart |
3228 |
0.84 |
17.49 |
25.75 |
0.0 |
0 |
0 |
30 |
9.00000e+01 |
▇▂▁▂▁ |
skim(lb23)
Data summary
| Name |
lb23 |
| Number of rows |
19205 |
| Number of columns |
10 |
| _______________________ |
|
| Column type frequency: |
|
| numeric |
10 |
| ________________________ |
|
| Group variables |
None |
Variable type: numeric
| año |
0 |
1.00 |
2023.00 |
0.00 |
2.0230e+03 |
2023 |
2023 |
2023 |
2.02300e+03 |
▁▁▇▁▁ |
| idenpa |
0 |
1.00 |
355.37 |
263.38 |
3.2000e+01 |
152 |
222 |
591 |
8.62000e+02 |
▇▆▂▃▃ |
| reg |
0 |
1.00 |
355524.26 |
263394.51 |
3.2001e+04 |
152016 |
222306 |
591902 |
8.62033e+05 |
▇▆▂▃▃ |
| ciudad |
0 |
1.00 |
355435981.89 |
263364138.58 |
3.2001e+07 |
152015001 |
222020302 |
591012004 |
8.62023e+08 |
▇▆▂▃▃ |
| wt |
0 |
1.00 |
1.00 |
0.56 |
2.7000e-01 |
1 |
1 |
1 |
4.40200e+01 |
▇▁▁▁▁ |
| aprobacion_pre |
1007 |
0.95 |
1.58 |
0.49 |
1.0000e+00 |
1 |
2 |
2 |
2.00000e+00 |
▆▁▁▁▇ |
| confianza_g |
197 |
0.99 |
2.99 |
0.99 |
1.0000e+00 |
2 |
3 |
4 |
4.00000e+00 |
▂▃▁▇▇ |
| party_id |
280 |
0.99 |
1.68 |
0.47 |
1.0000e+00 |
1 |
2 |
2 |
2.00000e+00 |
▃▁▁▁▇ |
| perpart |
0 |
1.00 |
2.97 |
1.25 |
1.0000e+00 |
2 |
4 |
4 |
4.00000e+00 |
▃▃▁▁▇ |
| fampart |
1558 |
0.92 |
16.50 |
25.05 |
0.0000e+00 |
0 |
0 |
30 |
9.00000e+01 |
▇▂▁▂▁ |
Union de datasets
lb18 <- as_factor(lb18)
lb20 <- as_factor(lb20)
lb23 <- as_factor(lb23)
lb_full <- bind_rows(lb23, lb20, lb18)
lb_full <- lb_full %>%
mutate(
año = as.character(año),
idenpa = as.character(idenpa),
reg = as.character(reg),
ciudad = as.character(ciudad),
wt = as.numeric(wt)
)
glimpse(lb_full)
## Rows: 59,613
## Columns: 10
## $ año <chr> "2023", "2023", "2023", "2023", "2023", "2023", "2023",~
## $ idenpa <chr> "32", "32", "32", "32", "32", "32", "32", "32", "32", "~
## $ reg <chr> "32001", "32001", "32001", "32001", "32001", "32001", "~
## $ ciudad <chr> "32001001", "32001001", "32001001", "32001001", "320010~
## $ wt <dbl> 41, 41, 41, 41, 41, 41, 26, 41, 41, 26, 41, 26, 41, 41,~
## $ aprobacion_pre <fct> 2, 2, 2, 2, 1, 2, 1, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2~
## $ confianza_g <fct> 4, 4, 4, 4, 2, 2, 2, 2, 2, 3, 4, 4, 3, 2, 4, 4, 4, 2, 4~
## $ party_id <fct> 2, 1, 1, 1, 2, 2, 2, 2, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2~
## $ perpart <fct> 3, 1, 1, 2, 1, 2, 1, 3, 2, 3, 2, 3, 2, 1, 3, 3, 3, 3, 3~
## $ fampart <fct> 0, 30, 30, 20, 30, 30, 30, 0, 60, 0, 30, 0, 60, 30, 0, ~
countries <- data.frame(
idenpa = c("32", "68", "76", "152", "170", "188", "214", "218", "222", "320",
"340", "484", "558", "591", "600", "604", "724", "858", "862"),
paises = c("Argentina", "Bolivia", "Brasil", "Chile", "Colombia", "Costa Rica",
"Rep. Dominicana", "Ecuador", "El Salvador", "Guatemala", "Honduras",
"México", "Nicaragua", "Panamá", "Paraguay", "Perú", "España", "Uruguay", "Venezuela"))
# Uniendo lb_full con country_mapping para obtener los nombres de los países
lb_full <- lb_full %>%
left_join(countries, by = "idenpa")
lb_full <- lb_full %>% select(año, idenpa, paises, everything())
Transformación de datos
lb_labels <- lb_full %>%
mutate(
aprobacion_pre = case_when(
aprobacion_pre == 1 ~ "Aprueba",
aprobacion_pre == 2 ~ "No aprueba",
is.na(aprobacion_pre) ~ "No precisa",
TRUE ~ as.character(aprobacion_pre)
),
confianza_g = factor(case_when(
confianza_g == 1 ~ "Mucha",
confianza_g == 2 ~ "Algo",
confianza_g == 3 ~ "Poca",
confianza_g == 4 ~ "Ninguna",
is.na(confianza_g) ~ "No precisa"
), levels = c("Mucha", "Algo", "Poca", "Ninguna", "No precisa"), ordered = TRUE),
party_id = case_when(
party_id == 1 ~ "Sí",
party_id == 2 ~ "No",
is.na(party_id) ~ "No precisa",
TRUE ~ as.character(party_id)
),
perpart = case_when(
perpart == 1 ~ "Gobierno",
perpart == 2 ~ "Oposición",
perpart == 3 ~ "Otro",
perpart == 4 ~ "No menciona partido",
TRUE ~ as.character(perpart)
),
fampart = case_when(
fampart == 10 ~ "Partidos Ecológicos",
fampart == 20 ~ "Partidos Comunistas",
fampart == 30 ~ "Partidos Social Demócratas",
fampart == 40 ~ "Partidos Liberales",
fampart == 50 ~ "Partidos Demócrata Cristianos",
fampart == 60 ~ "Partidos Conservadores",
fampart == 70 ~ "Partidos Nacionalistas",
fampart == 80 ~ "Partidos Agrarios",
fampart == 90 ~ "Partidos Étnicos y Regionales",
fampart == 95 ~ "Partidos con temas específicos",
fampart == 98 ~ "Alianzas Electorales de diverso origen",
fampart == 99 ~ "Perdidos",
fampart == 0 ~ "Perdidos",
is.na(fampart)~ "No precisa",
TRUE ~ as.character(fampart)
)
)
glimpse(lb_labels)
## Rows: 59,613
## Columns: 11
## $ año <chr> "2023", "2023", "2023", "2023", "2023", "2023", "2023",~
## $ idenpa <chr> "32", "32", "32", "32", "32", "32", "32", "32", "32", "~
## $ paises <chr> "Argentina", "Argentina", "Argentina", "Argentina", "Ar~
## $ reg <chr> "32001", "32001", "32001", "32001", "32001", "32001", "~
## $ ciudad <chr> "32001001", "32001001", "32001001", "32001001", "320010~
## $ wt <dbl> 41, 41, 41, 41, 41, 41, 26, 41, 41, 26, 41, 26, 41, 41,~
## $ aprobacion_pre <chr> "No aprueba", "No aprueba", "No aprueba", "No aprueba",~
## $ confianza_g <ord> Ninguna, Ninguna, Ninguna, Ninguna, Algo, Algo, Algo, A~
## $ party_id <chr> "No", "Sí", "Sí", "Sí", "No", "No", "No", "No", "Sí", "~
## $ perpart <chr> "Otro", "Gobierno", "Gobierno", "Oposición", "Gobierno"~
## $ fampart <chr> "Perdidos", "Partidos Social Demócratas", "Partidos Soc~
Confianza en el gobierno, oposición y oficialismo
¿Es posible inferir la confianza ciudadana en el gobierno a través
del análisis de la clasificación de las preferencias electorales en el
oficalismo y la oposición (2023)?”
lb_labels %>%
filter(paises %in% c("Bolivia", "Ecuador", "Perú", "Colombia"), año == "2023") %>%
ggplot(aes(x = confianza_g, fill = perpart)) +
geom_bar(position = "fill") +
facet_wrap(~ paises, nrow = 2, scales = "free_y") +
theme_minimal() +
labs(
x = "Confianza en el Gobierno", y = "Proporción (dentro de cada país)", fill = "Ubicación de la preferencia electoral") +
scale_y_continuous(labels = scales::percent_format()) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))

Confianza en el Gobierno e identificación partidista en AL
¿Cómo se expresó la relacion entre confianza en el gobierno e
identificación partidista durante el año 2023?
lb_labels %>%
filter(paises %in% c("Bolivia", "Ecuador", "Perú", "Colombia"), año == "2023") %>%
ggplot(aes(x = confianza_g, fill = party_id)) +
geom_bar(position = "fill") +
facet_wrap(~ paises, nrow = 2, scales = "free_y") +
theme_minimal() +
labs(
title = "Confianza en el Gobierno e identificación partidista en AL",
subtitle = "¿Cómo se expresó la relacion entre confianza en el gobierno e identificación partidista durante el año 2023",
x = "Nivel de Confianza en el Gobierno",
y = "Proporción (dentro de cada país)",
fill = "Identificación con Partido"
) +
scale_y_continuous(labels = scales::percent_format()) +
theme(
axis.text.x = element_text(angle = 45, hjust = 1),
plot.title = element_text(size = 10, face = "bold"),
plot.subtitle = element_text(size = 8)
)
