Last active
May 10, 2019 15:19
-
-
Save jsajuria/6e9e1654e27775997b5d6402372a06e8 to your computer and use it in GitHub Desktop.
Código para gráfico en https://twitter.com/jsajuria/status/1126479830793506820
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(texreg) | |
library(haven) | |
library(hrbrthemes) | |
library(ggrepel) | |
dat <- read_csv("controles_comunas.csv") ## Pueden bajar el archivo en el Gist | |
mod1 <- lm(controles ~ poly(poblacion,1) + poly(pobreza,2), dat) | |
screenreg(mod1) | |
p1 <- ggplot(dat, aes(x = poblacion, y = controles, color = Tipo)) + | |
geom_point(aes(size = pobreza), alpha = 0.7) + | |
scale_x_continuous("Población (Censo 2017)", breaks = c(0, 250000, 500000), limits = c(0,600000)) + | |
scale_y_continuous("Controles de Identidad") + | |
geom_smooth(method = "loess", se = FALSE, colour = "#636363", lty = 2) + | |
geom_smooth(method = "lm", se = FALSE, colour = "#feb24c", lty = 2, lwd = 1) + | |
geom_text_repel(data = dat, | |
aes(label = comuna), force = 2) + | |
theme_minimal() + | |
theme_ipsum_rc() + | |
labs(title = "Relación entre población y controles de identidad", | |
caption = "Fuentes: La Tercera; Censo 2017; Observatorio MDS \n Gráfico: @jsajuria" , | |
size="Pobreza \ncomunal (%)") | |
p1 | |
dat$ratio <- dat$controles/dat$poblacion | |
p2 <- ggplot(dat, aes(x = reorder(comuna, ratio), y=ratio, fill = Tipo)) + | |
geom_bar(stat = "identity") + | |
scale_x_discrete("Comunas") + | |
scale_y_continuous("Ratio Controles identidad/Población") + | |
theme_minimal() + | |
theme_ipsum_rc() + | |
coord_flip() + | |
labs(title = "Ranking de comunas por ratio entre controles de identidad y población", | |
caption = "Fuentes: La Tercera; Censo 2017; Observatorio MDS \n Gráfico: @jsajuria", | |
fill = "Tipo de Comuna" | |
) | |
p2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
comuna | controles | poblacion | pobreza | Rural | |
---|---|---|---|---|---|
Cerrillos | 22253 | 80832 | 8.1 | 0 | |
Cerro Navia | 35233 | 132622 | 12.1 | 0 | |
Conchalí | 42915 | 126955 | 10.2 | 0 | |
El Bosque | 25361 | 162505 | 14.5 | 0 | |
Estación Central | 60918 | 147041 | 6.2 | 0 | |
Huechuraba | 14841 | 98671 | 6.1 | 0 | |
Independencia | 14722 | 100281 | 9.8 | 0 | |
La Cisterna | 34083 | 90119 | 3.6 | 0 | |
La Florida | 40258 | 366916 | 3.1 | 0 | |
La Granja | 26234 | 116571 | 7.2 | 0 | |
La Pintana | 19004 | 177335 | 13.9 | 0 | |
La Reina | 25250 | 92787 | 2.3 | 0 | |
Las Condes | 30752 | 294838 | 0.6 | 0 | |
Lo Barnechea | 22581 | 105833 | 2.5 | 0 | |
Lo Espejo | 21037 | 98804 | 9.5 | 0 | |
Lo Prado | 19168 | 96249 | 5.7 | 0 | |
Macul | 26371 | 116534 | 5.3 | 0 | |
Maipú | 63092 | 521627 | 5.2 | 0 | |
Ñuñoa | 29932 | 208237 | 2.4 | 0 | |
PAC | 32981 | 101174 | 11 | 0 | |
Peñalolen | 24593 | 241599 | 4.8 | 0 | |
Providencia | 19400 | 142079 | 0.7 | 0 | |
Pudahuel | 63092 | 230293 | 7.8 | 0 | |
Puente Alto | 65289 | 568106 | 8 | 0 | |
Quilicura | 16316 | 210410 | 7.8 | 0 | |
Quinta Normal | 20463 | 110026 | 5.9 | 0 | |
Recoleta | 24144 | 157851 | 13.9 | 0 | |
Renca | 21147 | 147151 | 8.5 | 0 | |
San Bernardo | 15713 | 297262 | 9.2 | 0 | |
San Joaquín | 23006 | 94492 | 6.6 | 0 | |
San Miguel | 37883 | 107954 | 3.5 | 0 | |
San Ramon | 26182 | 82900 | 9.4 | 0 | |
Santiago | 109159 | 404495 | 5.9 | 0 | |
Vitacura | 11067 | 85384 | 0 | 0 | |
Talagante | 32531 | 74237 | 12 | 1 | |
Melipilla | 22989 | 123627 | 14 | 1 | |
Peñaflor | 17513 | 90201 | 7.9 | 1 | |
Buin | 17034 | 96614 | 10.3 | 1 | |
Colina | 14517 | 146207 | 12.6 | 1 | |
Lampa | 12540 | 102034 | 9.8 | 1 | |
San Jose de Maipo | 8988 | 18189 | 5.7 | 1 | |
Padre Hurtado | 6824 | 63250 | 10.3 | 1 | |
Pirque | 6818 | 26521 | 3.6 | 1 | |
El Monte | 6594 | 35923 | 6.1 | 1 | |
Isla de Maipo | 6207 | 36219 | 10.3 | 1 | |
Curacaví | 5646 | 32579 | 6.9 | 1 | |
Paine | 4839 | 72759 | 8.1 | 1 | |
Tiltil | 4832 | 19312 | 7.9 | 1 | |
Calera de Tango | 2197 | 25392 | 2.8 | 1 | |
María Pinto | 1377 | 13590 | 10.6 | 1 | |
Alhué | 1000 | 6444 | 10.5 | 1 | |
San Pedro | 149 | 9726 | 11.5 | 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment