README.md

PoliticalCandidates2019

R-CMD-check

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.

Installation

You can install the development version of PoliticalCandidates2019 from GitHub with:

# install.packages("devtools")
devtools::install_github("gchickering21/PoliticalCandidates2019")

Examples

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)
gender count percentage female 10742 32.67 male 22137 67.33

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)
race count percentage white 28577 88.44 black or african american 2029 6.28 hispanic or latino 1076 3.33 asian american or pacific islander 361 1.12 american indian or alaska native 128 0.40 multiracial 106 0.33 other 34 0.11

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()
office\_level Democratic Independent Republican regional 49.35 2.60 48.05 locality 25.42 70.76 3.81 country 54.89 0.64 44.47 administrativeArea2 27.06 10.32 62.62 administrativeArea1 47.49 1.86 50.65

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")
#> Warning: Removed 68 rows containing missing values (geom_point).

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")
#> Warning: Removed 68 rows containing missing values (geom_point).

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.



gchickering21/PoliticalCandidates2019 documentation built on Jan. 1, 2021, 2:17 a.m.