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(gapminder)
library(readr)
library(ggplot2)
library(knitr)

The Data

Data1 <- read_csv("~/Downloads/Abbreviated Dataset Labeled.csv") 
## Parsed with column specification:
## cols(
##   .default = col_character(),
##   NumChildren = col_double(),
##   Immigr_Economy_GiveTake = 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.

Religious Importance Table

new_Data1<-Data1%>%
  mutate(ReligiousImportance = factor(ReligiousImportance, levels = c("Very Important", 
                                                                       "Somewhat Important", 
                                                                      "Not too Important",  
                                                                      "Not at all Important")))%>%
  filter(PartyIdentification %in% c("Democrat", "Republican"))
table(new_Data1$ReligiousImportance,new_Data1$PartyIdentification)%>%
  prop.table(2)%>%
  round(2)
##                       
##                        Democrat Republican
##   Very Important           0.34       0.52
##   Somewhat Important       0.25       0.28
##   Not too Important        0.16       0.12
##   Not at all Important     0.25       0.08

Church Attendance Table

new_Data1<-Data1%>%
  mutate(ChurchAttendance = factor(ChurchAttendance, levels = c("Never", 
                                                                "Seldom",
                                                                "Once a week",
                                                                "More than once a week",
                                                                "Once or twice a month",
                                                                "A few times a year")))%>%
  filter(PartyIdentification %in% c("Democrat", "Republican"))
table(new_Data1$ChurchAttendance, new_Data1$PartyIdentification)%>%
  prop.table(2)%>%
  round(2)
##                        
##                         Democrat Republican
##   Never                     0.33       0.17
##   Seldom                    0.24       0.22
##   Once a week               0.15       0.26
##   More than once a week     0.06       0.13
##   Once or twice a month     0.08       0.09
##   A few times a year        0.13       0.14

Prayer Frequency Table

new_Data1<- Data1%>%
  mutate(PrayerFrequency = factor(PrayerFrequency, levels = c("Never",
                                                              "Seldom",
                                                              "Once a day",
                                                              "Several times a day",
                                                              "Once a week",
                                                              "A few times a month",
                                                              "A few times a week")))%>%
  filter(PartyIdentification %in% c("Democrat","Republican"))
table(new_Data1$PrayerFrequency,new_Data1$PartyIdentification)%>%
  prop.table(2)%>%
  round(2)
##                      
##                       Democrat Republican
##   Never                   0.20       0.06
##   Seldom                  0.15       0.13
##   Once a day              0.15       0.18
##   Several times a day     0.28       0.38
##   Once a week             0.02       0.02
##   A few times a month     0.06       0.07
##   A few times a week      0.14       0.15

Christianity Average and Histogram

Data1 %>%
  filter(PartyIdentification %in% c("Democrat","Republican")) %>%
  group_by(PartyIdentification)%>%
  summarize(AVG = mean(ft_christ_2017, na.rm=TRUE))
## # A tibble: 2 x 2
##   PartyIdentification   AVG
##   <chr>               <dbl>
## 1 Democrat             63.8
## 2 Republican           85.4
ggplot(data = new_Data1)+
geom_histogram(aes(x=ft_christ_2017), fill="dark green", bins = 50)+
facet_wrap(~PartyIdentification)
## Warning: Removed 2113 rows containing non-finite values (stat_bin).

Muslim Average and Histogram

Data1 %>%
  filter(PartyIdentification %in% c("Democrat","Republican")) %>%
  group_by(PartyIdentification)%>%
  summarize(AVG = mean(ft_muslim_2017, na.rm=TRUE))
## # A tibble: 2 x 2
##   PartyIdentification   AVG
##   <chr>               <dbl>
## 1 Democrat             62.8
## 2 Republican           34.8
ggplot(data = new_Data1)+
geom_histogram(aes(x=ft_muslim_2017), fill="dark blue", bins = 50)+
facet_wrap(~PartyIdentification)
## Warning: Removed 2202 rows containing non-finite values (stat_bin).