The API of the Brazilian Federal Senate can be explored with congressbr
by searching for details on individual senators, commissions and votes, among other options.
congressbr
can be installed by running:
if(!require(devtools)){install.packages("devtools", repos = "http://cran.us.r-project.org")}
if(!require(ggplot2)){install.packages("ggplot2", repos = "http://cran.us.r-project.org")}
library(congressbr)
library(ggplot2)
The voting behaviour of legislators is an area of great interest both inside and outside of academia. congressbr
has the sen_votes()
function, which returns a data frame of votes in the Senate. These are not necessarily nominal votes, as some may be secret votes. In this case, the API records whether the senator voted or not. The other variables in the data frame returned pertain to the time of the vote, its number, id, year, description and its result. Information on individual senators (their party, name, id, gender and state) is also returned. This function has an argument, binary
, which if TRUE
, transforms the recorded (nominal) votes from “Yes” to 1 and “No” to 0. This is handy if you want to use the wnominate, pscl or MCMCpack functions to run ideal point analyses, for example. Please note that dates are in “yyyymmdd
” format.
sen_votes(date = "20160908")
## # A tibble: 486 × 16
## vote_date vote_time vote_round bill_id bill_number bill_type bill_year
## <dttm> <chr> <dbl> <chr> <chr> <chr> <chr>
## 1 2016-09-08 14:00 1 126544 00076 MSF 2016
## 2 2016-09-08 14:00 1 126544 00076 MSF 2016
## 3 2016-09-08 14:00 1 126544 00076 MSF 2016
## 4 2016-09-08 14:00 1 126544 00076 MSF 2016
## 5 2016-09-08 14:00 1 126544 00076 MSF 2016
## 6 2016-09-08 14:00 1 126544 00076 MSF 2016
## 7 2016-09-08 14:00 1 126544 00076 MSF 2016
## 8 2016-09-08 14:00 1 126544 00076 MSF 2016
## 9 2016-09-08 14:00 1 126544 00076 MSF 2016
## 10 2016-09-08 14:00 1 126544 00076 MSF 2016
## # ... with 476 more rows, and 9 more variables: bill_description <chr>,
## # vote_result <chr>, vote_secret <chr>, senator_id <chr>,
## # senator_name <chr>, senator_vote <chr>, senator_gender <chr>,
## # senator_party <chr>, senator_state <chr>
For convenience, we have included a dataset of all nominal votes in the Federal Senate from 1991 to early 2017, which can be accessed with data("senate_nominal_votes")
. The dataset is only 38kB and can be loaded quickly on any computer.
If you want to know more about the results from the plenary in the Federal Senate for a specified date, you may also use the sen_plenary()
function. As an example, you can retrieve information from the session of the 3rd of March 2016 with:
sen_plenary_result(date = "20160303")
## # A tibble: 9 × 17
## bill_id
## <chr>
## 1 124978
## 2 125012
## 3 123432
## 4 123467
## 5 122838
## 6 83503
## 7 124453
## 8 122690
## 9 124879
## # ... with 16 more variables: bill <chr>, bill_type <chr>,
## # bill_number <chr>, bill_year <chr>, session_id <chr>,
## # session_number <chr>, session_date <dttm>, session_time <chr>,
## # session_type <chr>, session_type_abbr <chr>, session_house <chr>,
## # bill_house <chr>, bill_report <chr>, bill_details <chr>,
## # bill_result <chr>, bill_sponsor <chr>
Information on individual senators can be had with sen_senator_details()
. This function returns the senator’s id, name, party and state, as well as information on his/her date of birth, place of birth, their mandates, and office information such as email and correspondence address. If the senator is a titular senator, information on his/her deputies (suplentes) is available with sen_senator_suplentes()
. The senator’s votes can be had with sen_senator_votes()
, and their mandates with sen_senator_mandates()
. Information on the commissions that the senator has served on is available with sen_senator_commissions()
, and the bills that they sponsored or authored with sen_senator_bills()
. For information on absences and party affiliations, use sen_senator()
. All of these functions use the senator’s id (with the id
option). A data frame of all of these is available from the function sen_senator_list()
:
sen_senator_list()
## # A tibble: 81 × 17
## id name_full name_senator
## <chr> <chr> <chr>
## 1 4981 Acir Marcos Gurgacz Acir Gurgacz
## 2 5140 Airton Sandoval Santana Airton Sandoval
## 3 945 Alvaro Fernandes Dias Alvaro Dias
## 4 4988 Ana Amelia de Lemos Ana Amelia
## 5 5529 Antonio Augusto Junho Anastasia Antonio Anastasia
## 6 3 Antonio Carlos Valadares Antonio Carlos Valadares
## 7 715 Armando de Queiroz Monteiro Neto Armando Monteiro
## 8 5164 Ataides de Oliveira Ataides Oliveira
## 9 391 Aecio Neves da Cunha Aecio Neves
## 10 3823 Benedito de Lira Benedito de Lira
## # ... with 71 more rows, and 14 more variables: gender <chr>,
## # foto_url <chr>, page_url <chr>, office_email <chr>, party_abbr <chr>,
## # id_mandate <chr>, state <chr>, status <chr>,
## # num_legislature_first_term <chr>, first_term_start <dttm>,
## # first_term_end <dttm>, num_legislature_second_term <chr>,
## # second_term_start <dttm>, second_term_end <dttm>
sen_senator_details(id = "3398") # Cristovam Buarque
## # A tibble: 1 × 16
## senator_id senator_name senator_party_name
## <chr> <chr> <chr>
## 1 3398 Cristovam Buarque Partido Popular Socialista
## # ... with 13 more variables: senator_party_abbr <chr>,
## # senator_party_date_joined <dttm>, senator_state <chr>,
## # senator_status <chr>, senator_gender <chr>,
## # senator_date_of_birth <dttm>, senator_state_of_birth <chr>,
## # senator_title <chr>, senator_mandates_first_legis <chr>,
## # senator_mandates_second_legis <chr>, senator_url <chr>,
## # senator_email <chr>, senator_office_address <chr>
sen_senator_bills(id = "3398")
## # A tibble: 90 × 9
## senator_id senator_name senator_party_name
## <chr> <chr> <chr>
## 1 3398 Cristovam Buarque Partido Popular Socialista
## 2 3398 Cristovam Buarque Partido Popular Socialista
## 3 3398 Cristovam Buarque Partido Popular Socialista
## 4 3398 Cristovam Buarque Partido Popular Socialista
## 5 3398 Cristovam Buarque Partido Popular Socialista
## 6 3398 Cristovam Buarque Partido Popular Socialista
## 7 3398 Cristovam Buarque Partido Popular Socialista
## 8 3398 Cristovam Buarque Partido Popular Socialista
## 9 3398 Cristovam Buarque Partido Popular Socialista
## 10 3398 Cristovam Buarque Partido Popular Socialista
## # ... with 80 more rows, and 6 more variables: senator_party_abbr <chr>,
## # senator_state <chr>, senator_bills_number <chr>,
## # senator_bills_type <chr>, senator_bills_year <chr>,
## # senator_bills_details <chr>
There are certain legislative coalitions in the Senate, all of whom have unique id numbers in the API database. These numbers can be accessed with sen_coalitions()
. Further information on the coalition of interest can be had with sen_coalition_info()
. For example, the Bloco Moderador (moderate bloc) has the id 200. We can obtain more detailed information on the coalition by using this id with the code
option:
sen_coalition_info(code = 200)
## # A tibble: 5 × 11
## bloc_code house bloc_name bloc_label date_created
## <chr> <chr> <chr> <chr> <dttm>
## 1 200 Bloco Bloco Moderador Bloco PTB, PR, PSC, PRB 2015-02-01
## 2 200 Bloco Bloco Moderador Bloco PTB, PR, PSC, PRB 2015-02-01
## 3 200 Bloco Bloco Moderador Bloco PTB, PR, PSC, PRB 2015-02-01
## 4 200 Bloco Bloco Moderador Bloco PTB, PR, PSC, PRB 2015-02-01
## 5 200 Bloco Bloco Moderador Bloco PTB, PR, PSC, PRB 2015-02-01
## # ... with 6 more variables: coalition_id <chr>, member_code <chr>,
## # member_data_joined <dttm>, member_abbr <chr>, member_name <chr>,
## # member_date_created <dttm>
A data frame of commissions (full name and abbreviation) can be obtained with data("commissions")
. The sen_commissions()
function returns a detailed dataframe of commissions, their ids, type, house and purpose. Commissions can be explored by type
variable returned from this function. For example, the “cpi” type (Comissão de Inquérito Parlamentar, Parliamentary Inquiry Commission) can be used in the sen_commissions_type()
function, which will return a data frame of commissions of the type specified.
Using the commission abbreviations, we can see which senators serve on the commission. One well-known commission is the Commission for the Constitution, Justice and Citizenship (Constituicao, Justica e Cidadania). Its abbreviation is “CCJ”:
data("commissions")
sen_commissions_senators(code = "CCJ")
## # A tibble: 52 × 6
## commission commission_abbr
## <chr> <chr>
## 1 Comissao de Constituicao, Justica e Cidadania CCJ
## 2 Comissao de Constituicao, Justica e Cidadania CCJ
## 3 Comissao de Constituicao, Justica e Cidadania CCJ
## 4 Comissao de Constituicao, Justica e Cidadania CCJ
## 5 Comissao de Constituicao, Justica e Cidadania CCJ
## 6 Comissao de Constituicao, Justica e Cidadania CCJ
## 7 Comissao de Constituicao, Justica e Cidadania CCJ
## 8 Comissao de Constituicao, Justica e Cidadania CCJ
## 9 Comissao de Constituicao, Justica e Cidadania CCJ
## 10 Comissao de Constituicao, Justica e Cidadania CCJ
## # ... with 42 more rows, and 4 more variables: senator_id <chr>,
## # senator_name <chr>, senator_party <chr>, senator_state <chr>
A list of the parties who have held seats in the Senate can be had with sen_parties()
:
sen_parties()
## # A tibble: 46 × 4
## party_id party_abbr party_name date_created
## <chr> <chr> <chr> <chr>
## 1 554 DEM Democratas 2007-03-28
## 2 566 NOVO Partido Novo 2015-09-15
## 3 142 PAN Partido dos Aposentados da Nacao 1998-02-19
## 4 94 PCB Partido Comunista Brasileiro 1922-03-25
## 5 144 PCN Partido Comunitario Nacional 1985-07-01
## 6 145 PCO Partido da Causa Operaria 1997-09-30
## 7 86 PCdoB Partido Comunista do Brasil 1962-02-01
## 8 20 PDT Partido Democratico Trabalhista 1980-09-16
## 9 559 PEN Partido Ecologico Nacional 2012-06-19
## 10 146 PF Partido Federalista 1900-01-01
## # ... with 36 more rows
For some functions, there are options to narrow the search by focusing on certain states. If you are not familiar with all of the Brazilian states or with their commonly-used abbreviations, use the UF()
function to print out a list of these abbreviations. For the full names of the states and their abbreviations, use data("statesBR")
.
UF()
## [1] "AC" "AL" "AP" "AM" "BA" "CE" "DF" "ES" "GO" "MA" "MT" "MS" "MG" "PA"
## [15] "PB" "PR" "PE" "PI" "RJ" "RN" "RS" "RO" "RR" "SC" "SP" "SE"
The Senate API can be queried by the type of bill. If you are not familiar with the types of bills that come to the Senate floor, use sen_bills_types()
. Other similar functions, useful for getting to know the Senate, are sen_plenary_sessions()
, which returns data on the types of sessions held in the Senate, sen_bills_topics()
, which returns a data frame with the topic labels for different subject categories.
The bill types can be used for other queries, such as for seeing what bills of a certain type are currently passing through the house. For example, we can see which MPVs (medida provisória; executive decree) were under consideration in the Senate in 2001:
sen_bills_passing(year = "2001", type = "MPV")
## # A tibble: 49 × 4
## bill_id bill_number bill_year bill_type
## <chr> <chr> <chr> <chr>
## 1 48017 02162 2001 MPV
## 2 48018 02163 2001 MPV
## 3 48019 02167 2001 MPV
## 4 48020 02170 2001 MPV
## 5 48021 02172 2001 MPV
## 6 48022 02173 2001 MPV
## 7 48025 02189 2001 MPV
## 8 48032 02161 2001 MPV
## 9 48034 02165 2001 MPV
## 10 48036 02190 2001 MPV
## # ... with 39 more rows
This function can also be used to get information for a single date.
congressbr
also has functions for accessing budget information (sen_budget()
), and the agenda in the Senate for a particular date, or range of dates:
sen_agenda(initial_date = "20161105", end_date = "20161125")
## # A tibble: 87 × 12
## agenda_id agenda_title
## <chr> <chr>
## 1 5551 CCS, as 09h, 15ª, Reuniao
## 2 5537 CDH, as 10h, 94ª, Extraordinaria
## 3 5553 CCS, as 14h, 16ª, Reuniao
## 4 5576 CJD, as 14h:30, 17ª, Reuniao
## 5 5591 CDH, as 15h, 95ª, Extraordinaria
## 6 5563 CCT, as 08h:45, 33ª, Extraordinaria
## 7 5535 CDH, as 09h, 96ª, Extraordinaria
## 8 5578 CMA, as 09h:30, 19ª, Extraordinaria
## 9 5598 CCJ,CAE, as 10h, 7ª, Conjunta
## 10 5581 CTG, as 11h, 15ª, Extraordinaria
## # ... with 77 more rows, and 10 more variables: agenda_name <chr>,
## # agenda_type <chr>, agenda_date <dttm>, agenda_time <chr>,
## # agenda_status <chr>, agenda_place <chr>,
## # agenda_commission_house <chr>, agenda_commission_abbr <chr>,
## # agenda_commission_id <chr>, agenda_commission_meeting_number <chr>
congressbr
can be used for various types of analyses. As a quick example, let’s explore the distribution of men and women currently sitting in the house. (This example makes use of the ggplot2 package.)
all_sens <- sen_senator_list()
ggplot2::ggplot(all_sens, aes(x = gender)) +
geom_bar(aes(fill = gender), colour = "white") +
theme_classic() +
scale_fill_manual(values = c("#45C74A", "#FFFF00"))
Looking at the distribution of Titular senators and deputies (suplentes) is also straightforward:
theme_classic() +
scale_fill_manual(values = c("#45C74A", "navy")) +
theme(legend.position = "none") +
coord_flip()
Which states have the most suplentes?
if(!require(dplyr)){install.packages("dplyr", repos = "http://cran.us.r-project.org")}
library(dplyr)
all_sens %>% filter(status != "Titular") %>% group_by(state) %>%
summarise(totals = n()) %>% arrange(desc(totals))
## # A tibble: 12 × 2
## state totals
## <chr> <int>
## 1 MT 2
## 2 BA 1
## 3 DF 1
## 4 GO 1
## 5 MG 1
## 6 MS 1
## 7 PB 1
## 8 PI 1
## 9 RJ 1
## 10 SC 1
## 11 SP 1
## 12 TO 1
Mato Grosso, it seems, with two-thirds of their senators being stand-in suplentes.