pollingBR
was created to give an easier access to data from the data repository of electoral polls from Poder360's news website. The package facilitates extraction of information from the open data API - developed by Volt Data Lab - of this repository.
The package has four main functions, all with similar arguments. Each of them correspond to one of the offices for which there are electoral polls in the data repository:
president()
for polls to the Presidency;governor()
for polls to the Governorship of the 26 Brazilian states and its Federal District;senator()
for polls to Senatorial seats of the 26 Brazilian states and its Federal District;mayor()
for polls to Mayor in more than 200 Brazilian cities.Besides those main functions, the package also includes:
get_cities()
that returns a data.frame
containing the complete list for cities in which there are polls for mayoral elections in Brazil and the corresponding years for which they are available.No momento, o pacote pollingBR
pode ser instalado diretamente da sua página no github:
if (!require("devtools")) install.packages("devtools") devtools::install_github("voltdatalab/pollingBR")
Assim como os demais pacotes em R, uma vez instalado, ele deve ser carregado com a função library()
.
library(pollingBR)
Those four functions that extract estimates of electoral polls for president, governor, senator and mayor have a similar basic structure. All of them return a dataframe
in which each line has the estimate for a candidate in a certain electoral poll. They have four arguments: year
, state
, type
and round
(except for the senator()
which does not include this last one).
year
argument should always be specified and informs the election year for which the user wishes to extract polls.# Extract data for all polls presidential polls in the 2018 elections president_2018 <- president(2018) # Get data for all gubernatorial polls in the 2014 elections governor_2014 <- governor(2014)
state
argument indicates the geographical level the poll is representative of. The default returns polls for all states and cities (besides the national-level polls, in the presidential elections). The user can specify only one or a few states by using their acronyms (or filter only by national-level polls, in the case of the president()
function, using the "BR"
acronym).# Extract data for all national-level polls for president in 2014 president_br_2014 <- president(2014, state = "BR") # Get data for all senatorial polls in Brazilian southern states in 2010 senate_south_2010 <- senator(2010, state = c("RS", "SC", "PR"))
type
argument designates the type of response the estimate corresponds to: spontaneous (1), stimulated (2) or rejection (3). Default returns estimates for all three possibilites (usually, results reported by the Brazilian media are from stimulated responses). The user can specify only one or more possibilities of responses.# Obtem dados de respostas espontaneas e estimuladas para pesquisas para o senado em SP no ano de 2006 senate_sp_2006 <- senator(2006, state = "SP", type = c(1, 2)) # Extrai dados de respostas de rejeicao em pesquisas nacionais para presidente em 2018 president_rejection_2018 <- president(2018, state = "BR", type = 3)
round
argument registers if the extracted data are from the first or second round of the elections (default returns estimates for both rounds). Senatorial elections are disputed in only one orund, so the senator()
function does not include this optional argument.# Extract data from all stimulated responses for polls in the first round of mayoral elections in 2012 mayor_2012_1r <- mayor(2012, type = 2, round = 1)
The get_cities()
function returns a data.frame
with a complete list of the cities with mayoral electoral polls in Poder360's data repository, accompanied by the election years for which they are available. Thus, users have an easier access to which municipal polls are available for them.
In the following example, we can see the first six lines of this data frame, showing that there are polls available for the mayoral races in the cities of Cruzeiro do Sul (only in 2008) and Rio Branco (in the election years between 2000 and 2016).
cities_polls <- get_cities() head(cities_polls)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.