Skip to content

Instantly share code, notes, and snippets.

@gabrielzanlorenssi
Created September 21, 2022 23:56
Show Gist options
  • Save gabrielzanlorenssi/33699ce8e7bb3808bf035ec4633f5aaa to your computer and use it in GitHub Desktop.
Save gabrielzanlorenssi/33699ce8e7bb3808bf035ec4633f5aaa to your computer and use it in GitHub Desktop.
#-- exemplo
cidade = "SÃO PAULO"
uf = "SP"
final %>%
mutate(partido = case_when(partido %in% c("PT", "PSDB", "PSOL") ~ partido,
numero_cand == 17 & year==2018 ~ "Bolsonaro",
numero_cand == 20 & year==1989 ~ "Collor",
numero_cand == 12 & year<1998 ~ "Brizola",
numero_cand == 40 & year==2014 ~ "Marina",
numero_cand == 43 & year==2010 ~ "Marina",
numero_cand == 18 & year==2018 ~ "Marina",
numero_cand == 12 & year==2018 ~ "Ciro",
numero_cand == 40 & year==1998 ~ "Ciro",
numero_cand == 23 & year==2002 ~ "Ciro",
numero_cand == 56 ~ "Enéas",
TRUE ~ "outros")) %>%
mutate(partido = fct_relevel(partido,
"Enéas", "Bolsonaro", "Collor", "PSDB",
"outros", "Marina", "Ciro",
"Brizola", "PT", "PSOL")) %>%
mutate(turno = paste0(turno," ° turno")) %>%
#filter(ibge7==29513) %>%
filter(muni==stringi::stri_trans_general(cidade, "latin-ascii"), uf==uf) %>%
#filter(uf == "MG") %>%
ggplot(aes(x=as.character(year), y=votos, fill=partido)) +
geom_col(position = "fill") +
facet_grid(rows=vars(turno)) +
geom_hline(yintercept = .5, alpha=.75, linetype="dashed") +
geom_hline(yintercept = .25, linetype="dotted", size=.20) +
geom_hline(yintercept = .75, linetype="dotted", size=.25) +
scale_y_continuous(labels=scales::percent) +
labs(y="Percentual", x="Eleição", caption="@gzanlorenssi",
title=paste0(cidade, " (", uf, ")")) +
scale_fill_manual(values=c('black', '#1b1464',
'#2e3192',
'#0071bc',
'#999999',
'#39b54a',
'#93278f',
'#9e005d',
'#c1272d',
'#ffff00'), drop=F, "partido/cand.") +
theme(text = element_text(family="Bahnschrift", size=12),
plot.title = element_text(size=24)) +
theme(panel.spacing = unit(1.15, "lines"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment