knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of PoliticalCandidates2019 is to be able to provide a framework to work with data that contains information on those that ran and for political offices all across the country at all the different levels of government and whether or not they won their race. The data available in this package also contains demographic information of the candidates themselves such as race and gender as well as the party they chose to affiliate themselves with. This data can be useful in being able to see and answer questions that breakdown these candidates by areas such as by levels of office, by state, by party, or by gender just to list a few examples.
You can install the development version of PoliticalCandidates2019 from GitHub with:
# install.packages("devtools") devtools::install_github("gchickering21/PoliticalCandidates2019")
These are a few basic examples which shows you the type of questions that can be answered by looking at this dataset.
library(PoliticalCandidates2019) library(tidyverse) options(dplyr.summarise.inform = FALSE) library(knitr) library(kableExtra)
This is an example showing how you can see the gender breakdown of who ran for positions at all levels of government.
gender_percents <- PoliticalCandidates2019 %>% select(gender) %>% filter(gender != "unknown" & gender != "other" ) %>% group_by(gender) %>% summarize(count = n()) %>% mutate(percentage = count / sum(count) * 100, percentage=round(percentage,2)) knitr::kable(gender_percents)
This is another example where we can see the racial demographics of the different types of candidates running for office.
race_percents <- PoliticalCandidates2019 %>% select(race) %>% filter(race != "unknown") %>% group_by(race) %>% summarize(count = n()) %>% mutate(percentage = count / sum(count) * 100, percentage=round(percentage,2)) %>% arrange(desc(percentage)) knitr::kable(race_percents)
This is another example that shows a breakdown of how often a party won a race, broken down by the different levels of government.
level_party_percents <- PoliticalCandidates2019 %>% select(office_level, party_roll_up, winner_y_n) %>% filter((party_roll_up == "Democratic" | party_roll_up == "Republican" | party_roll_up == "Independent") & winner_y_n == "Yes") %>% group_by(office_level, party_roll_up) %>% summarize(count = n()) %>% mutate(percentage = count / sum(count) * 100, percentage=round(percentage,2)) %>% select(office_level, party_roll_up, percentage) level_party_percents %>% pivot_wider(names_from = "party_roll_up", values_from = "percentage") %>% arrange(desc(office_level)) %>% knitr::kable()
This is another example of a type of plot that could be generated by the data in this package where we examine the relationship between number of times elected by race for the different political parties.
ggplot(PoliticalCandidates2019, aes(x = number_elected, y = race, color = party_roll_up)) + geom_point(position = position_jitter(width = 0.2, height = 0.4)) + labs(x = "Number of Times Elected", y = "Race", title = "Race and Being Elected")
This is one last example that shows how one can examine the relationship between number of times elected by race at the different levels of government.
ggplot(PoliticalCandidates2019, aes(x = number_elected, y = office_level, color = race)) + geom_point(position = position_jitter(width = 0.15, height = 0.3)) + labs(x = "Number of Times Elected", y = "Race", title = "Race at Different Levels of Gov't")
These are just a couple examples of the types of information that can be drawn and the analysis that can be done with the data from this R Package.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.