-
Notifications
You must be signed in to change notification settings - Fork 7
/
dieciseis.R
67 lines (55 loc) · 2.36 KB
/
dieciseis.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# #30díasdegráficos día 16
# Visualización participación femenina parlamentos latinoamérica
# https://raw.githubusercontent.com/cienciadedatos/datos-de-miercoles/master/datos/2019/2019-05-08/datos_uip.csv
# Autora: Stephanie Orellana (@sporella)
# Cargar librerías --------------------------------------------------------
library(tidyverse)
library(waffle) # devtools::install_gitlab("hrbrmstr/waffle")
# Cargar y procesar datos -------------------------------------------------
paises <- c("Argentina", "Bolivia", "Brasil", "Chile", "Colombia", "Ecuador",
"Paraguay", "Perú", "Uruguay", "Venezuela")
datos <- read_csv(
"https://raw.githubusercontent.com/cienciadedatos/datos-de-miercoles/master/datos/2019/2019-05-08/datos_uip.csv"
) %>%
filter(pais %in% paises) %>%
select(pais, camara, porcentaje_mujeres) %>%
mutate(porcentaje_mujeres = ceiling(porcentaje_mujeres),
porcentaje_hombres = 100 - porcentaje_mujeres) %>%
pivot_longer(3:4,
names_to = "genero",
values_to = "porcentaje",
names_prefix = "porcentaje_", values_drop_na = T) %>%
arrange(camara) %>%
mutate(pais = factor(pais, levels = unique(pais)),
camara = str_c("Cámara ", camara),
genero = factor(genero, levels = c("mujeres", "hombres"),
labels = c("Mujeres", "Hombres")))
# Visualización -----------------------------------------------------------
p <- ggplot(datos, aes(fill = genero, values = porcentaje)) +
geom_waffle(
n_rows = 20,
size = 0.33,
colour = "white",
flip = TRUE
) +
facet_wrap(pais ~ camara,
ncol = 3,
dir = "v",
strip.position = "bottom") +
scale_fill_manual(values = c("#ae9dff", "#46ecce")) +
labs(title = "Participación Femenina\nParlamentos de Latinoamérica",
fill = "",
caption = "@sporella") +
theme(line = element_blank(), rect = element_blank(),
axis.text = element_blank(),
axis.title = element_blank(),
axis.ticks = element_blank(),
strip.text.x = element_text(size = 8, margin = margin(0,5,0,5), vjust=1),
legend.position = "bottom",
plot.caption.position = "panel",
plot.title = element_text(
size = 15,
vjust = 2,
hjust = 0.5
))
ggsave("plots/dieciseis/parlamentos.png",p, width = 5, height = 5)