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.
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:
# 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() glimpse(regions)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.