Safiya

Sociology 333

Instructor Turner

10/22/2018


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

VoterData<-read_csv("/Users/safiesaf/Downloads/VOTER_Survey_July17_Release1-csv.csv")
## Parsed with column specification:
## cols(
##   .default = col_integer(),
##   weight_2017 = col_double(),
##   redovote2016_t_2017 = col_character(),
##   job_title_t_2017 = col_character(),
##   weight_2016 = col_double(),
##   izip_2016 = col_character(),
##   presvote16post_t_2016 = col_character(),
##   second_chance_t_2016 = col_character(),
##   race_other_2016 = col_character(),
##   healthcov_t_2016 = col_character(),
##   employ_t_2016 = col_character(),
##   pid3_t_2016 = col_character(),
##   religpew_t_2016 = col_character(),
##   votemeth16_rnd_2016 = col_character(),
##   presvote16post_rnd_2016 = col_character(),
##   vote2016_cand2_rnd_2016 = col_character(),
##   Clinton_Rubio_rnd_2016 = col_character(),
##   Clinton_Cruz_rnd_2016 = col_character(),
##   Sanders_Trump_rnd_2016 = col_character(),
##   Sanders_Rubio_rnd_2016 = col_character(),
##   second_chance_rnd_2016 = col_character()
##   # ... with 123 more columns
## )
## See spec(...) for full column specifications.
New2Data<-VoterData%>%
  rename("Gender"=gender_baseline,
         "AreaLived"=urbancity_baseline)%>%
  mutate(Gender=ifelse(Gender==1,"Male",
                ifelse(Gender==2,"Female",NA)),
         AreaLived=ifelse(AreaLived==1,"City",
                    ifelse(AreaLived==2,"Suburb",
                    ifelse(AreaLived==3,"Town",
                    ifelse(AreaLived==4,"Rural Area",
                    ifelse(AreaLived==5,"Other",NA))))))%>%
select(Gender,AreaLived)

head(New2Data)
## # A tibble: 6 x 2
##   Gender AreaLived 
##   <chr>  <chr>     
## 1 Female Suburb    
## 2 Female Rural Area
## 3 Male   City      
## 4 Male   City      
## 5 Male   Suburb    
## 6 Female Suburb
kable(head(New2Data))
Gender AreaLived
Female Suburb
Female Rural Area
Male City
Male City
Male Suburb
Female Suburb
#AreaLivedChart<-New2Data%>%
 #group_by(Gender)%>%
 #summarize(AreaLived)%>%
#ggplot(data=AreaLivedChart)+
 #geom_col(aes(x=Gender,y=AreaLived))

In this assignment, the two categorical variables used were Gender and Area Lived. The question asked:-

Does gender affect the type of area lived?

The frequency, Area Lived, was compared to the level, Gender, to observe if Gender had any impact on the type of area lived. Based on the results of the bar chart, it seems there is little to no impact on area lived when it comes to gender.

New2Data%>%
group_by(AreaLived,Gender)%>%
summarize(n=n())%>%
mutate(percent=n/sum(n))%>%
filter(AreaLived=="City"|
       AreaLived=="Suburb"|
       AreaLived=="Town"|
       AreaLived=="Rural Area",
       Gender=="Female")%>%
  ggplot()+
  ggtitle("Does Gender Affect Area Lived")+
geom_col(aes(x=AreaLived,y=percent),fill="purple")

head(New2Data)
## # A tibble: 6 x 2
##   Gender AreaLived 
##   <chr>  <chr>     
## 1 Female Suburb    
## 2 Female Rural Area
## 3 Male   City      
## 4 Male   City      
## 5 Male   Suburb    
## 6 Female Suburb

```