library(tidyverse)
## Registered S3 methods overwritten by 'ggplot2':
## method from
## [.quosures rlang
## c.quosures rlang
## print.quosures rlang
## Registered S3 method overwritten by 'rvest':
## method from
## read_xml.response xml2
## -- Attaching packages ---------------------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.1.1 v purrr 0.3.2
## v tibble 2.1.1 v dplyr 0.8.0.1
## v tidyr 0.8.3 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.4.0
## -- Conflicts ------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(formattable)
## Warning: package 'formattable' was built under R version 3.6.1
dt_16 <- electionsBR::candidate_local(2016)
## Processing the data...
## Done.
can_eleitos <- dt_16 %>%
filter(DESCRICAO_CARGO == "VEREADOR", DES_SITUACAO_CANDIDATURA == "APTO") %>%
group_by(SIGLA_PARTIDO,DESC_SIT_TOT_TURNO) %>%
summarise(n = n()) %>%
ungroup() %>%
group_by(SIGLA_PARTIDO) %>%
mutate(total_cand_part = sum (n)) %>%
ungroup() %>%
filter(DESC_SIT_TOT_TURNO %in% c("ELEITO POR MÉDIA","ELEITO POR QP")) %>%
group_by(SIGLA_PARTIDO) %>%
mutate(eleitos = sum (n)) %>%
ungroup() %>%
select(-c(DESC_SIT_TOT_TURNO,n)) %>%
arrange(desc(eleitos)) %>%
distinct(SIGLA_PARTIDO, .keep_all = T)
formattable(can_eleitos,
list (total_cand_part = color_bar("lightgreen"),
eleitos = color_bar("lightgreen")))
|
SIGLA_PARTIDO
|
total_cand_part
|
eleitos
|
|
PMDB
|
38476
|
7564
|
|
PSDB
|
31161
|
5363
|
|
PP
|
24655
|
4742
|
|
PSD
|
25752
|
4644
|
|
PDT
|
23065
|
3770
|
|
PSB
|
23744
|
3633
|
|
PTB
|
19937
|
3065
|
|
PR
|
20051
|
3018
|
|
DEM
|
19333
|
2902
|
|
PT
|
20882
|
2814
|
|
PPS
|
15017
|
1674
|
|
PRB
|
16117
|
1620
|
|
PSC
|
14835
|
1529
|
|
PV
|
15249
|
1522
|
|
SD
|
13446
|
1437
|
|
PC do B
|
10861
|
1008
|
|
PROS
|
9877
|
984
|
|
PSL
|
9516
|
878
|
|
PHS
|
10721
|
877
|
|
PTN
|
8808
|
763
|
|
PRP
|
7744
|
613
|
|
PTC
|
7951
|
573
|
|
PMN
|
6582
|
525
|
|
PEN
|
9208
|
524
|
|
PT do B
|
6732
|
489
|
|
PSDC
|
6820
|
419
|
|
PRTB
|
5870
|
391
|
|
PMB
|
4024
|
216
|
|
REDE
|
3285
|
180
|
|
PPL
|
3194
|
111
|
|
PSOL
|
4086
|
56
|
|
NOVO
|
136
|
4
|
|
PCB
|
189
|
1
|