---
title: "Results of the 2018 Brazilian Presidential election"
output: rmarkdown::html_vignette
author: Fábio N. Demarqui
vignette: >
  %\VignetteIndexEntry{Results of the 2018 Brazilian Presidential election}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

This vignette aims to show how the results of the 2018 Brazilian presidential election can be combined with data from the COVID-19 pandemic.

```{r, message=FALSE, fig.dim = c(7, 5)}
library(covid19br)
library(tidyverse)

# loading the election data:
data(election2018Cities)

# looking at the data:
glimpse(election2018Cities)

election2018Cities <- election2018Cities %>%
  add_geo() %>%
  mutate(
    prop = 100*Bolsonaro/(Bolsonaro + Haddad),
  ) %>%
  pivot_longer(cols = c("Bolsonaro", "Haddad"), values_to = "votes", names_to = "candidate")


ggplot(election2018Cities) +
  geom_sf(aes(fill = prop)) +
  labs(fill = "% votes")

```

The 2018 Brazilian presidential election results observed in Minas Gerais (MG) state, for instance, can be easily extracted from the data set `election2018Cities` as illustrated below:

```{r, message=FALSE, fig.dim = c(7, 5)}

# extracting the data:
mg_election <- election2018Cities %>%
  filter(state == "MG")

# visualizing:
ggplot(mg_election) +
  geom_sf(aes(fill = prop)) +
  labs(fill = "% votes")

```

The package __covid19br__ also provides datasets containing Development Human Indexes (DHI) at city (`ipeaCities`), state (`ipeaStates`) and region (`ipeaRegions`) levels. The code presented below shows how to combine the COVID-19 data (at region level) with the election and the DHI datasets.

<!-- Putting all together:  -->

```{r}

# loading the election data:
data(election2018Regions)

  # putting all together 
regions <- downloadCovid19("regions") %>%
  filter(date == max(date)) %>%
  add_epi_rates() %>%
  left_join(election2018Regions) %>%
  add_geo()

glimpse(regions)
```


<!-- ```{r} -->
<!-- # https://ourworldindata.org/covid-vaccinations -->
<!-- ``` -->

