-
Notifications
You must be signed in to change notification settings - Fork 0
/
Writeup.qmd
57 lines (32 loc) · 8.15 KB
/
Writeup.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
title: "Write Up"
subtitle: "STA/ISS 313 - Project 2"
author: "Team Spring"
format: html
editor: visual
---
## Link to app
<https://rawalmalika123.shinyapps.io/project-2-team_spring-v2/>
## Introduction
Our team had a keen interest in United States politics especially with the 2024 National Election coming up. North Carolina was the best state to investigate as students of a North Carolina University and as North Carolina is usually considered a swing state. Our research question is: How do North Carolina Presidential election trends correlate to demographics and how has this changed over time? We are very interested in understanding the breakdown of votes and demographics by county to understand which counties are especially determining the state's outcome every election. We will be examining the breakdown of Democratic vs. Republican votes by county over the last six elections as well as the breakdown of different demographics in those counties. We decided to focus on sex, age and race for the specific demographics and we are only examining votes for Presidential elections. Our app presents users with dynamic maps, tables, and an animated visualization and is intended for policymakers and the general public to have an accessible tool that allows them to analyze North Carolina's political trends, and especially how demographic trends coorrelate with voting patterns throughout the previous six elections.
## Data
In order to study these breakdowns we found 12 data sets - 6 for the affiliation of votes by county and 6 for the demographic breakdown of voters by county. Each election year from 2000-2020 has two data sets. We found the 6 data sets for affiliation from the North Carolina Board of Elections and for the census data we used dataset from the Office of State Budget and Management. For the election data we used variables like `Total Votes`, `Choice Party` and `County` and from the ACS data we used `age_category`, `sex`, and `race`. We also used a dataset that had the latitude and longitude coordinates of each county in North Carolina as well as a 6 datasets that had the population by county for each of the 6 years we were examining. We used census data for the population per county for accuracy, thus the only updates in population are made every 10 years instead of 4 years per election.
## Approach
Our first step once finding the datasets was to clean them and combine the individual 6 datasets for the election into 1 data set and the individual 6 datasets for the ACS data into one dataset. In order to clean the election data we had to read in the individual text files, rename the columns, filter for only Presidential results and then filter for only the variables we wanted. We also need to add another column that had the year of the election. Once we did this for all 6 of the text files turned into csv files we combined them all together into `election_data`, and then joined with another dataset called `separate_geo` that contained the latitude and longitude coordinates for each county and called this new data `election_data_wide_geo`. We then created another dataset called `combined_population` by combining the 6 datasets we found with the population by county for each of the 6 elections years into a single data set with the population for each year and then we joined `combined_population` with `election_data_wide_geo` and created two new columns that contained the democratic votes per capita and the republican votes.
Next we cleaned the ACS data which just included reading in each csv for each year and filtering for the variables we wanted and then binding all 6 of those datasets into one `ASC_all`.
Now that we had our cleaned data, in order to show these breakdowns by county we will use a Shiny app with two leaflet maps. The first map allows the user to filter by election and county. It shows the breakdown of Democratic vs. Republican votes by population for the specific election chosen and colors from a red to purple scale. It also highlights the the county chosen, so it is easier to view specific counties. When you click on a county an overview of the number of Republican and Democratic votes is shown.
The second leaflet map shows voting demographics for the same elections and allows to filter by either sex, race, age or a combination of the three. The map also colors by the filters chosen by percentage of population on a green to white scale. The filters allow users to determine what could be causing the changes in voting affiliation, whether that's race, age, population, or all three combined.
We chose to use a shiny app with two leaflet maps because it allows easy examination of the differences from year to year, county to county and from specific filters. We also added an animation at the end that shows the county breakdown of dem votes vs. rep votes over the 6 elections to get a better idea of how the individual counties changed. Layering the shiny app and leaflet maps allows the user to zoom in and zoom out as they please to see the rest of the United States' map.
## Analysis
A trend that we were following throughout the making of this project was how strongly race correlated with election votes. For example, in 2000, counties that had the most significant votes for the democratic party were also counties that had large Black populations. Specific counties include: Warren (32% Dem votes for the GOP and 26.12% Black Population), NorthHampton (33% Dem votes for the GOP and 28.58% Black Population), and Hertford (30% Dem votes for the GOP and 28.21% Black Population). Over time, we noticed the coorelation between race and democrat votes tapering off in these counties and lessening. For example, in the counties we mentioned, in 2020, Warren had 37% Dem votes for the GOP but only a 24% Black Population, NorthHampton had 40% Dem votes for the GOP but only a 27.16% Black population, and lastly, Hertford had 33% Dem votes for the GOP and a 28.27% Black Population.
Additionally, we noticed increasing political polarization in North Carolina over time. Looking at the animated plot of Political Distribution in North Carolina over time, we can notice the "blue" and "red" becoming of a darker hue in many of the same counties over time. Indicating that counties become either more "red" or more "blue" distancing from a neutral stance. There is data to support that political polarization has been on the "up" since the election of 2016 (Donald Trump vs Hillary Clinton) and it was interesting to see the North Carolina data support this conclusion as especially in 2016 and 2020 the intensity of the hues indicating republican or democrat votes increased.
## Conclusion
In conclusion, our Shiny app allows users to view electoral trends alongside demographic changes in North Carolina over the past six elections. By integrating the two, users can get a holistic sense of the causes behind the electoral trends in North Carolina and the reasons behind the "swing state" nature of NC. Our findings underscored the importance of race, sex, and age \[need to add more to prove this in the analysis section\] have had on election data, but has highlighted the significant polarization occurring in the state.
By creating three different facets to display information (leaflet plots, data tables, and animated visualizations) we are allowing the user to understand the intricacies behind the changing voter trends in North Carolina as well as enabling policymakers to make educated predictions for the 2024 National Election.
We hope that this project allows all North Carolinian's and politics enthusiasts to understand the complex voter dynamics that occur in the state and contributed to more informed policy discussions in the near future.
## **Sources**
Election Data:<https://www.ncsbe.gov/results-data/election-results/historical-election-results-data#by-precinct>
Demographics Data:<https://www.osbm.nc.gov/facts-figures/population-demographics>
Layering a Shiny App onto Leaflet:<https://rstudio.github.io/leaflet/articles/shiny.html>
Data tables in Shiny:<https://shiny.posit.co/r/articles/build/datatables/>
Allowing the User to Select the \# of Rows in the Datatable:<https://forum.posit.co/t/getting-the-user-selected-entry-of-a-data-table-in-shiny-to-actually-make-a-scatterplot/52419>