Data 607 Assignment 1

Eddie Xu


link

Introduction

Gun control is a polarizing topic in America, especially in 2018. The article cover the topic and presents the poll of Gun Control in America. Because of that, I want to find out about the average of adults and registered voter.

Conclusion

Based on my analysis, it appears that registered voters are more vocal about gun control.

### Load Libraries
library(ggplot2)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.2 --
## v tibble  3.1.6      v dplyr   1.0.10
## v tidyr   1.2.0      v stringr 1.5.0 
## v readr   2.1.2      v forcats 0.5.2 
## v purrr   1.0.1
## Warning: package 'tibble' was built under R version 4.0.5
## Warning: package 'tidyr' was built under R version 4.0.5
## Warning: package 'readr' was built under R version 4.0.5
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()

Read the CSV file

readfile <- data.frame(read.csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/poll-quiz-guns/guns-polls.csv", header = TRUE))
dim(readfile)
## [1] 57  9
head(readfile)
##   Question   Start     End           Pollster        Population Support
## 1   age-21 2/20/18 2/23/18           CNN/SSRS Registered Voters      72
## 2   age-21 2/27/18 2/28/18          NPR/Ipsos            Adults      82
## 3   age-21  3/1/18  3/4/18          Rasmussen            Adults      67
## 4   age-21 2/22/18 2/26/18 Harris Interactive Registered Voters      84
## 5   age-21  3/3/18  3/5/18         Quinnipiac Registered Voters      78
## 6   age-21  3/4/18  3/6/18             YouGov Registered Voters      72
##   Republican.Support Democratic.Support
## 1                 61                 86
## 2                 72                 92
## 3                 59                 76
## 4                 77                 92
## 5                 63                 93
## 6                 65                 80
##                                                                                                                                               URL
## 1                                                                                http://cdn.cnn.com/cnn/2018/images/02/25/rel3a.-.trump,.guns.pdf
## 2                   https://www.ipsos.com/en-us/npripsos-poll-majority-americans-support-policies-aimed-keep-guns-out-hands-dangerous-individuals
## 3 http://www.rasmussenreports.com/public_content/lifestyle/general_lifestyle/march_2018/americans_favor_raising_age_to_buy_gun_not_enlist_or_vote
## 4                                                                http://thehill.com/opinion/civil-rights/375993-americans-support-no-gun-under-21
## 5                                                                                      https://poll.qu.edu/national/release-detail?ReleaseID=2525
## 6                                                     https://d25d2506sfb94s.cloudfront.net/cumulus_uploads/document/zq33h2ipcl/econTabReport.pdf

remove a column

poll_df <- readfile %>% select(-c(URL))
head(poll_df)
##   Question   Start     End           Pollster        Population Support
## 1   age-21 2/20/18 2/23/18           CNN/SSRS Registered Voters      72
## 2   age-21 2/27/18 2/28/18          NPR/Ipsos            Adults      82
## 3   age-21  3/1/18  3/4/18          Rasmussen            Adults      67
## 4   age-21 2/22/18 2/26/18 Harris Interactive Registered Voters      84
## 5   age-21  3/3/18  3/5/18         Quinnipiac Registered Voters      78
## 6   age-21  3/4/18  3/6/18             YouGov Registered Voters      72
##   Republican.Support Democratic.Support
## 1                 61                 86
## 2                 72                 92
## 3                 59                 76
## 4                 77                 92
## 5                 63                 93
## 6                 65                 80

What is the poll support that are greater than 50?

library(knitr)
Support_50 <- subset(poll_df, Support > 50)
Support_50
##                       Question   Start     End            Pollster
## 1                       age-21 2/20/18 2/23/18            CNN/SSRS
## 2                       age-21 2/27/18 2/28/18           NPR/Ipsos
## 3                       age-21  3/1/18  3/4/18           Rasmussen
## 4                       age-21 2/22/18 2/26/18  Harris Interactive
## 5                       age-21  3/3/18  3/5/18          Quinnipiac
## 6                       age-21  3/4/18  3/6/18              YouGov
## 7                       age-21  3/1/18  3/5/18     Morning Consult
## 14           background-checks 2/16/18 2/19/18          Quinnipiac
## 15           background-checks 2/18/18 2/20/18              YouGov
## 16           background-checks 2/25/18 2/27/18              YouGov
## 17           background-checks 2/15/18 2/19/18     Morning Consult
## 18           background-checks 2/20/18 2/23/18            CBS News
## 19           background-checks 2/27/18 2/28/18           NPR/Ipsos
## 20           background-checks  3/1/18  3/5/18     Morning Consult
## 21         ban-assault-weapons 2/16/18 2/19/18          Quinnipiac
## 22         ban-assault-weapons 2/18/18 2/20/18              YouGov
## 23         ban-assault-weapons 2/25/18 2/27/18              YouGov
## 24         ban-assault-weapons 2/15/18 2/19/18     Morning Consult
## 25         ban-assault-weapons 2/15/18 2/18/18 ABC/Washington Post
## 26         ban-assault-weapons 2/20/18 2/23/18            CNN/SSRS
## 27         ban-assault-weapons 2/20/18 2/23/18            CBS News
## 28         ban-assault-weapons 2/16/18 2/19/18      Harvard/Harris
## 29         ban-assault-weapons 2/20/18 2/24/18             Suffolk
## 30         ban-assault-weapons 2/27/18 2/28/18           NPR/Ipsos
## 31         ban-assault-weapons  3/3/18  3/5/18          Quinnipiac
## 32         ban-assault-weapons  3/1/18  3/5/18     Morning Consult
## 33 ban-high-capacity-magazines 2/18/18 2/20/18              YouGov
## 34 ban-high-capacity-magazines 2/25/18 2/27/18              YouGov
## 35 ban-high-capacity-magazines 2/15/18 2/19/18     Morning Consult
## 36 ban-high-capacity-magazines 2/20/18 2/23/18            CNN/SSRS
## 37 ban-high-capacity-magazines 2/27/18 2/28/18           NPR/Ipsos
## 38 ban-high-capacity-magazines  3/3/18  3/5/18          Quinnipiac
## 39 ban-high-capacity-magazines  3/1/18  3/5/18     Morning Consult
## 40       mental-health-own-gun 2/18/18 2/20/18              YouGov
## 41       mental-health-own-gun 2/25/18 2/27/18              YouGov
## 42       mental-health-own-gun 2/15/18 2/19/18     Morning Consult
## 43       mental-health-own-gun 2/20/18 2/24/18             Suffolk
## 44       mental-health-own-gun 2/27/18 2/28/18           NPR/Ipsos
## 45       mental-health-own-gun  3/1/18  3/5/18     Morning Consult
## 47           stricter-gun-laws 2/27/18 2/28/18           NPR/Ipsos
## 48           stricter-gun-laws 2/25/18 2/27/18              YouGov
## 49           stricter-gun-laws 2/20/18 2/23/18            CNN/SSRS
## 50           stricter-gun-laws 2/20/18 2/23/18            CBS News
## 51           stricter-gun-laws 2/20/18 2/21/18              Marist
## 52           stricter-gun-laws 2/18/18 2/20/18              YouGov
## 53           stricter-gun-laws 2/16/18 2/19/18          Quinnipiac
## 54           stricter-gun-laws 2/22/18 2/26/18     Morning Consult
## 55           stricter-gun-laws  3/3/18  3/5/18          Quinnipiac
## 56           stricter-gun-laws  3/4/18  3/6/18              YouGov
## 57           stricter-gun-laws  3/1/18  3/5/18     Morning Consult
##           Population Support Republican.Support Democratic.Support
## 1  Registered Voters      72                 61                 86
## 2             Adults      82                 72                 92
## 3             Adults      67                 59                 76
## 4  Registered Voters      84                 77                 92
## 5  Registered Voters      78                 63                 93
## 6  Registered Voters      72                 65                 80
## 7  Registered Voters      76                 72                 86
## 14 Registered Voters      97                 97                 99
## 15 Registered Voters      85                 78                 87
## 16 Registered Voters      83                 76                 91
## 17 Registered Voters      88                 88                 90
## 18            Adults      75                 66                 86
## 19            Adults      94                 89                 99
## 20 Registered Voters      90                 91                 91
## 21 Registered Voters      67                 43                 91
## 22 Registered Voters      61                 45                 79
## 23 Registered Voters      58                 37                 82
## 24 Registered Voters      69                 64                 81
## 25 Registered Voters      51                 29                 71
## 26 Registered Voters      57                 34                 80
## 27            Adults      53                 39                 66
## 28 Registered Voters      61                 43                 76
## 29 Registered Voters      63                 40                 83
## 30            Adults      72                 58                 88
## 31 Registered Voters      61                 38                 88
## 32 Registered Voters      68                 41                 83
## 33 Registered Voters      67                 52                 82
## 34 Registered Voters      64                 44                 82
## 35 Registered Voters      69                 63                 82
## 36 Registered Voters      64                 48                 82
## 37            Adults      73                 59                 88
## 38 Registered Voters      63                 39                 87
## 39 Registered Voters      71                 64                 84
## 40 Registered Voters      87                 87                 84
## 41 Registered Voters      84                 81                 86
## 42 Registered Voters      88                 89                 90
## 43 Registered Voters      76                 84                 78
## 44            Adults      92                 88                 96
## 45 Registered Voters      88                 91                 91
## 47            Adults      75                 59                 92
## 48 Registered Voters      63                 43                 87
## 49 Registered Voters      70                 49                 93
## 50            Adults      65                 43                 85
## 51 Registered Voters      73                 55                 93
## 52 Registered Voters      58                 36                 76
## 53 Registered Voters      66                 34                 86
## 54 Registered Voters      68                 53                 89
## 55 Registered Voters      63                 39                 88
## 56 Registered Voters      61                 42                 82
## 57 Registered Voters      69                 57                 85
kable(Support_50, caption = "Poll Greater Than 50")
Poll Greater Than 50
Question Start End Pollster Population Support Republican.Support Democratic.Support
1 age-21 2/20/18 2/23/18 CNN/SSRS Registered Voters 72 61 86
2 age-21 2/27/18 2/28/18 NPR/Ipsos Adults 82 72 92
3 age-21 3/1/18 3/4/18 Rasmussen Adults 67 59 76
4 age-21 2/22/18 2/26/18 Harris Interactive Registered Voters 84 77 92
5 age-21 3/3/18 3/5/18 Quinnipiac Registered Voters 78 63 93
6 age-21 3/4/18 3/6/18 YouGov Registered Voters 72 65 80
7 age-21 3/1/18 3/5/18 Morning Consult Registered Voters 76 72 86
14 background-checks 2/16/18 2/19/18 Quinnipiac Registered Voters 97 97 99
15 background-checks 2/18/18 2/20/18 YouGov Registered Voters 85 78 87
16 background-checks 2/25/18 2/27/18 YouGov Registered Voters 83 76 91
17 background-checks 2/15/18 2/19/18 Morning Consult Registered Voters 88 88 90
18 background-checks 2/20/18 2/23/18 CBS News Adults 75 66 86
19 background-checks 2/27/18 2/28/18 NPR/Ipsos Adults 94 89 99
20 background-checks 3/1/18 3/5/18 Morning Consult Registered Voters 90 91 91
21 ban-assault-weapons 2/16/18 2/19/18 Quinnipiac Registered Voters 67 43 91
22 ban-assault-weapons 2/18/18 2/20/18 YouGov Registered Voters 61 45 79
23 ban-assault-weapons 2/25/18 2/27/18 YouGov Registered Voters 58 37 82
24 ban-assault-weapons 2/15/18 2/19/18 Morning Consult Registered Voters 69 64 81
25 ban-assault-weapons 2/15/18 2/18/18 ABC/Washington Post Registered Voters 51 29 71
26 ban-assault-weapons 2/20/18 2/23/18 CNN/SSRS Registered Voters 57 34 80
27 ban-assault-weapons 2/20/18 2/23/18 CBS News Adults 53 39 66
28 ban-assault-weapons 2/16/18 2/19/18 Harvard/Harris Registered Voters 61 43 76
29 ban-assault-weapons 2/20/18 2/24/18 Suffolk Registered Voters 63 40 83
30 ban-assault-weapons 2/27/18 2/28/18 NPR/Ipsos Adults 72 58 88
31 ban-assault-weapons 3/3/18 3/5/18 Quinnipiac Registered Voters 61 38 88
32 ban-assault-weapons 3/1/18 3/5/18 Morning Consult Registered Voters 68 41 83
33 ban-high-capacity-magazines 2/18/18 2/20/18 YouGov Registered Voters 67 52 82
34 ban-high-capacity-magazines 2/25/18 2/27/18 YouGov Registered Voters 64 44 82
35 ban-high-capacity-magazines 2/15/18 2/19/18 Morning Consult Registered Voters 69 63 82
36 ban-high-capacity-magazines 2/20/18 2/23/18 CNN/SSRS Registered Voters 64 48 82
37 ban-high-capacity-magazines 2/27/18 2/28/18 NPR/Ipsos Adults 73 59 88
38 ban-high-capacity-magazines 3/3/18 3/5/18 Quinnipiac Registered Voters 63 39 87
39 ban-high-capacity-magazines 3/1/18 3/5/18 Morning Consult Registered Voters 71 64 84
40 mental-health-own-gun 2/18/18 2/20/18 YouGov Registered Voters 87 87 84
41 mental-health-own-gun 2/25/18 2/27/18 YouGov Registered Voters 84 81 86
42 mental-health-own-gun 2/15/18 2/19/18 Morning Consult Registered Voters 88 89 90
43 mental-health-own-gun 2/20/18 2/24/18 Suffolk Registered Voters 76 84 78
44 mental-health-own-gun 2/27/18 2/28/18 NPR/Ipsos Adults 92 88 96
45 mental-health-own-gun 3/1/18 3/5/18 Morning Consult Registered Voters 88 91 91
47 stricter-gun-laws 2/27/18 2/28/18 NPR/Ipsos Adults 75 59 92
48 stricter-gun-laws 2/25/18 2/27/18 YouGov Registered Voters 63 43 87
49 stricter-gun-laws 2/20/18 2/23/18 CNN/SSRS Registered Voters 70 49 93
50 stricter-gun-laws 2/20/18 2/23/18 CBS News Adults 65 43 85
51 stricter-gun-laws 2/20/18 2/21/18 Marist Registered Voters 73 55 93
52 stricter-gun-laws 2/18/18 2/20/18 YouGov Registered Voters 58 36 76
53 stricter-gun-laws 2/16/18 2/19/18 Quinnipiac Registered Voters 66 34 86
54 stricter-gun-laws 2/22/18 2/26/18 Morning Consult Registered Voters 68 53 89
55 stricter-gun-laws 3/3/18 3/5/18 Quinnipiac Registered Voters 63 39 88
56 stricter-gun-laws 3/4/18 3/6/18 YouGov Registered Voters 61 42 82
57 stricter-gun-laws 3/1/18 3/5/18 Morning Consult Registered Voters 69 57 85

Bar plot

What is the poll average in gun control by Population?

poll_average_df <- subset(poll_df, select = -c(Start, End, Pollster))
head(poll_average_df)
##   Question        Population Support Republican.Support Democratic.Support
## 1   age-21 Registered Voters      72                 61                 86
## 2   age-21            Adults      82                 72                 92
## 3   age-21            Adults      67                 59                 76
## 4   age-21 Registered Voters      84                 77                 92
## 5   age-21 Registered Voters      78                 63                 93
## 6   age-21 Registered Voters      72                 65                 80
poll_average_df <- poll_average_df %>%
  select(Population, Support) %>%
  group_by(Population) %>%
  mutate(
    pop_avg = mean(Support)
  )

ggplot(poll_average_df, aes(Population, pop_avg, fill = Population)) + 
         geom_bar(stat = "identity", position = "dodge") +
         labs(title = "Poll Average in Population")