Results of the 2018 Brazilian Presidential election

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

library(covid19br)
library(tidyverse)

# loading the election data:
data(election2018Cities)

# looking at the data:
glimpse(election2018Cities)
#> Rows: 5,570
#> Columns: 11
#> $ region           <chr> "North", "North", "North", "North", "North", "North",…
#> $ state            <chr> "AC", "AC", "AC", "AC", "AC", "AC", "AC", "AC", "AC",…
#> $ city             <chr> "Acrelândia", "Assis Brasil", "Brasiléia", "Bujari", …
#> $ region_code      <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ state_code       <dbl> 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1…
#> $ mesoregion_code  <int> 1202, 1202, 1202, 1202, 1202, 1201, 1202, 1201, 1201,…
#> $ microregion_code <int> 12004, 12005, 12005, 12004, 12004, 12001, 12005, 1200…
#> $ city_code        <int> 120001, 120005, 120010, 120013, 120017, 120020, 12002…
#> $ Bolsonaro        <int> 5165, 2333, 8711, 4676, 3895, 31147, 6284, 6296, 1375…
#> $ Haddad           <int> 1300, 1660, 3208, 1274, 1086, 7818, 2026, 5256, 1415,…
#> $ pop              <dbl> 15256, 7417, 26278, 10266, 11733, 88376, 18411, 34780…

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:


# 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.


# loading the election data:
data(election2018Regions)

  # putting all together 
regions <- downloadCovid19("regions") %>%
  filter(date == max(date)) %>%
  add_epi_rates() %>%
  left_join(election2018Regions) %>%
  add_geo()
#> Downloading COVID-19 data from the official Brazilian repository: https://covid.saude.gov.br/
#> Please, be patient...
#>  Done!
#> Joining, by = c("region", "pop")
#> Joining, by = c("region", "pop")

glimpse(regions)
#> Rows: 5
#> Columns: 23
#> $ region       <chr> "Midwest", "North", "Northeast", "South", "Southeast"
#> $ date         <date> 2021-10-16, 2021-10-16, 2021-10-16, 2021-10-16, 2021-10-1…
#> $ epi_week     <int> 41, 41, 41, 41, 41
#> $ newCases     <int> 1534, 766, 1846, 2934, 4170
#> $ accumCases   <int> 2310360, 1854070, 4821086, 4192933, 8460277
#> $ newDeaths    <int> 36, 11, 62, 85, 289
#> $ accumDeaths  <int> 57886, 46690, 117511, 94458, 286607
#> $ newRecovered <int> NA, NA, NA, NA, NA
#> $ newFollowup  <int> NA, NA, NA, NA, NA
#> $ pop          <dbl> 16297074, 18430980, 57071654, 29975984, 88371433
#> $ incidence    <dbl> 14176.533, 10059.530, 8447.426, 13987.641, 9573.543
#> $ lethality    <dbl> 2.51, 2.52, 2.44, 2.25, 3.39
#> $ mortality    <dbl> 355.1926, 253.3235, 205.9008, 315.1123, 324.3209
#> $ Bolsonaro    <int> 5163023, 4242504, 8824454, 11084395, 28351800
#> $ Haddad       <int> 2595426, 3933015, 20289812, 5152685, 15016238
#> $ DHI          <dbl> 0.6894678, 0.6079510, 0.5906721, 0.7141128, 0.6989844
#> $ EDHI         <dbl> 0.5841416, 0.4904276, 0.4884060, 0.6130152, 0.6081894
#> $ LDHI         <dbl> 0.8224442, 0.7803808, 0.7543157, 0.8353316, 0.8281859
#> $ IDHI         <dbl> 0.6844893, 0.5928241, 0.5622705, 0.7134444, 0.6811571
#> $ region_code  <dbl> 5, 1, 2, 4, 3
#> $ area         [km^2] 1611899.2 [km^2], 3870624.8 [km^2], 1560644.5 [km^2], 56…
#> $ demoDens     [1/km^2] 10.110480 [1/km^2], 4.761758 [1/km^2], 36.569286 [1/km^2]…
#> $ geometry     <GEOMETRY [°]> POLYGON ((-54.08399 -23.864..., POLYGON ((-68.38821 -11.0…