#install.packages("dplyr")
#install.packages("ggplot2")
#install.packages("knitr")
#install.packages("tidyr")
#install.packages("readr")
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(knitr)
library(tidyr)
library(readr)
voterdata <- read_csv("C:/Users/PLESLIE100/Desktop/R Studio Class Work/Abbreviated Dataset Labeled(October Only)V2(1).csv")
## Parsed with column specification:
## cols(
## .default = col_character(),
## NumChildren = col_double(),
## ft_fem_2017 = col_double(),
## ft_immig_2017 = col_double(),
## ft_police_2017 = col_double(),
## ft_dem_2017 = col_double(),
## ft_rep_2017 = col_double(),
## ft_evang_2017 = col_double(),
## ft_muslim_2017 = col_double(),
## ft_jew_2017 = col_double(),
## ft_christ_2017 = col_double(),
## ft_gays_2017 = col_double(),
## ft_unions_2017 = col_double(),
## ft_altright_2017 = col_double(),
## ft_black_2017 = col_double(),
## ft_white_2017 = col_double(),
## ft_hisp_2017 = col_double()
## )
## See spec(...) for full column specifications.
names(voterdata)
## [1] "gender" "race"
## [3] "education" "familyincome"
## [5] "children" "region"
## [7] "urbancity" "Vote2012"
## [9] "Vote2016" "TrumpSanders"
## [11] "PartyRegistration" "PartyIdentification"
## [13] "PartyIdentification2" "PartyIdentification3"
## [15] "NewsPublicAffairs" "DemPrimary"
## [17] "RepPrimary" "ImmigrantContributions"
## [19] "ImmigrantNaturalization" "ImmigrationShouldBe"
## [21] "Abortion" "GayMarriage"
## [23] "DeathPenalty" "DeathPenaltyFreq"
## [25] "TaxWealthy" "Healthcare"
## [27] "GlobWarmExist" "GlobWarmingSerious"
## [29] "AffirmativeAction" "Religion"
## [31] "ReligiousImportance" "ChurchAttendance"
## [33] "PrayerFrequency" "NumChildren"
## [35] "areatype" "GunOwnership"
## [37] "ft_fem_2017" "ft_immig_2017"
## [39] "ft_police_2017" "ft_dem_2017"
## [41] "ft_rep_2017" "ft_evang_2017"
## [43] "ft_muslim_2017" "ft_jew_2017"
## [45] "ft_christ_2017" "ft_gays_2017"
## [47] "ft_unions_2017" "ft_altright_2017"
## [49] "ft_black_2017" "ft_white_2017"
## [51] "ft_hisp_2017"
“ft_rep_2017”, “ft_black_2017”, “race”, “PartyRegistration”,“PartyIdentification”, “ft_white_2017”, “ft_dem_2017”, “ft_hisp_2017”
Topic 2: Party & Race
How do the democrat & republican parties differ in the racial/ethnic composition of their members?
How do they differ in their attitudes towards various ethnic groups?
Therefore we need need to examine the following variables “PartyIdentification” and “Race” to answer part one of the question that will be a cross tabulation. To determine how the republicans and democrats differ in their attitudes between the races we must run averages using the following variables for part two of the question “PartyIdentification”, “ft_black_2017”, “ft_white_2017”, “ft_hisp_2017”
voterdata%>%
filter(!is.na(PartyIdentification))%>%
filter(!is.na(race))%>%
group_by(PartyIdentification, race)%>%
summarise(n=n())%>%
mutate(percent=n/sum(n))%>%
ggplot()+
geom_col(aes(PartyIdentification, y=percent, fill=race))+
coord_flip()
voterdata%>%
filter(!is.na(PartyIdentification))%>%
filter(PartyIdentification %in% c("Democrat", "Republican"))%>%
group_by(PartyIdentification)%>%
summarise(avg_ft_blacks = mean(ft_black_2017, na.rm = TRUE), avg_ft_whites =mean(ft_white_2017, na.rm = TRUE), avg_ft_hispanics = mean(ft_hisp_2017, na.rm = TRUE))%>%
gather(group, rating, -PartyIdentification)
## # A tibble: 6 x 3
## PartyIdentification group rating
## <chr> <chr> <dbl>
## 1 Democrat avg_ft_blacks 77.9
## 2 Republican avg_ft_blacks 65.7
## 3 Democrat avg_ft_whites 74.3
## 4 Republican avg_ft_whites 80.9
## 5 Democrat avg_ft_hispanics 74.5
## 6 Republican avg_ft_hispanics 66.2
voterdata%>%
filter(!is.na(PartyIdentification))%>%
filter(PartyIdentification %in% c("Democrat", "Republican"))%>%
ggplot()+
geom_histogram(aes(x=ft_black_2017, fill=PartyIdentification))+
facet_wrap(~PartyIdentification)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 2121 rows containing non-finite values (stat_bin).
voterdata%>%
filter(!is.na(PartyIdentification))%>%
filter(PartyIdentification %in% c("Democrat", "Republican"))%>%
ggplot()+
geom_histogram(aes(x=ft_white_2017, fill=PartyIdentification))+
facet_wrap(~PartyIdentification)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 2104 rows containing non-finite values (stat_bin).
voterdata%>%
filter(!is.na(PartyIdentification))%>%
filter(PartyIdentification %in% c("Democrat", "Republican"))%>%
ggplot()+
geom_histogram(aes(x=ft_hisp_2017, fill=PartyIdentification))+
facet_wrap(~PartyIdentification)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 2129 rows containing non-finite values (stat_bin).