Last active
October 10, 2024 16:50
-
-
Save leoniedu/b62bdd1c5b5fa4b0e67621c4c48f3044 to your computer and use it in GitHub Desktop.
Eficiência do voto nas eleições para Prefeito no Brasil (1º Turno 2024 )
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(dplyr) | |
library(ggplot2) | |
library(ggrepel) | |
library(readr) | |
## votacao por municipio, candidato e cargo | |
vmc <- readr::read_rds("~/Downloads/20241007_151828_eleicao24_prefeitos_vereadores_finalizados.rds") | |
## por cargo, municipio, partido | |
vmp <- vmc%>% | |
## vitoria (conta passar pro segundo turno) | |
mutate(s=situacao_candidato_turno%in%c("Eleito", "Eleito por QP", "Eleito por média", "2º turno"))%>% | |
group_by(cargo, sg_partido_fix=gsub("\\*", "*", sg_partido), cd_municipio_ibge)%>% | |
summarise(v=sum(as.numeric(votos_abs), na.rm=TRUE), | |
s=sum(as.numeric(s), na.rm=TRUE))%>% | |
group_by(cargo, cd_municipio_ibge)%>% | |
mutate( | |
eleitorado=sum(v), | |
p=s/sum(s), | |
q=p*sum(v) | |
) | |
## por cargo, partido | |
vp <- vmp%>% | |
#filter(eleitorado>1000e3)%>% | |
#filter(substr(cd_municipio_ibge,1,2)==29)%>% | |
group_by(cargo, sg_partido_fix)%>% | |
summarise(v=sum(v, na.rm=TRUE), | |
s=sum(s, na.rm=TRUE), | |
q=sum(q, na.rm=TRUE))%>% | |
group_by(cargo)%>% | |
mutate( | |
r=q/sum(q, na.rm=TRUE), | |
t=v/sum(v, na.rm=TRUE) | |
) | |
cnow <- "Prefeito" | |
#cnow <- "Vereador" | |
library(hrbrthemes) | |
ggplot(aes(y=r/t, x=t), data=vp%>%filter(s>0, cargo==cnow))+ | |
geom_point(aes(size=s), color="red") + | |
geom_label_repel(aes(label=sg_partido_fix)) + facet_grid(~cargo)+ | |
labs(x="Votos", y="Eficiência dos votos\n(Eleitorado representado*/Votos)", size="Número de eleitos*", caption = "* Candidatos que passaram para o 2º turno representam 50% do votos totais do município e contam como 'eleitos'") + | |
scale_x_continuous(labels=scales::percent, limits=c(0,.15), expand=c(0,0) | |
) + | |
scale_y_continuous(labels=scales::percent, limits=c(0,1.3), expand=c(0,0) | |
) +hrbrthemes::theme_ft_rc() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment