Loading Packages

library(graphics)
library(ggplot2)
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 3.6.3
## -- Attaching packages ------------------------------------------------ tidyverse 1.3.0 --
## v tibble  2.1.3     v dplyr   0.8.4
## v tidyr   1.0.2     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## v purrr   0.3.3
## Warning: package 'tidyr' was built under R version 3.6.3
## Warning: package 'dplyr' was built under R version 3.6.3
## Warning: package 'stringr' was built under R version 3.6.3
## Warning: package 'forcats' was built under R version 3.6.3
## -- Conflicts --------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(knitr)
## Warning: package 'knitr' was built under R version 3.6.3
library(gridExtra)
## Warning: package 'gridExtra' was built under R version 3.6.3
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
library(ggpubr)
## Warning: package 'ggpubr' was built under R version 3.6.3
## Loading required package: magrittr
## 
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
## 
##     set_names
## The following object is masked from 'package:tidyr':
## 
##     extract
library(rstatix)
## Warning: package 'rstatix' was built under R version 3.6.3
## 
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
## 
##     filter
setwd("C:/Users/Daivik/Desktop/EDA/Assignments/Assignment 2")

Question 2a

data <-  read.csv("anes_pilot_2020ets_csv.csv", header = TRUE)
anes_new <- subset(data, select = c("fttrump1", "ftbiden1", "ftsanders1", "ftbuttigieg1"))
anes_new <- filter(anes_new, anes_new$fttrump1 <= 100, anes_new$ftbiden1 <= 100,anes_new$ftsanders1 <= 100, anes_new$ftbuttigieg1 <= 100)
anes_new<- gather(anes_new, key = "Presidential_candidate", value = "feeling_temperature", c('fttrump1', 'ftbiden1', 'ftsanders1', 'ftbuttigieg1'))

ggplot(anes_new,aes(x = feeling_temperature , fill = Presidential_candidate)) +
  geom_histogram(bins = 20) + 
  facet_wrap(~Presidential_candidate, ncol = 1) + 
  theme_bw() + 
  scale_fill_discrete(name ="Presidential Candidate", labels = c("Donald Trump", "Joe Biden", "Bernie Sanders", "Pete Buttigieg")) + 
  ggtitle("Distribution of Feeling Temperature Scores of Political Candidates") + 
  xlab("Temeperature") +
  ylab("Number of people")

Conclusion: Biden’s distribution almost appears to be a symmetric distribution.Most of the people have varied opinions on Biden.The people who feel very cold are almsot equal to people who feel very warm. But, we see two peaks at the cold and moderate level. Could be Bi-Modal considering others to be a flat line. Pete’s distribution is almost similar to Biden’s with Bi-Modal peaks. Sanders has a multi-modal distribution with varying opinions but very similar to Pete and Biden. Trump’s graph is almost similar to the distribution graph of Biden but in this graph people who feel very warm are less in number than people who felt very warm in Biden’s case. Greater peak at the cold area for Trump.

Question 2b

anes_cov <- subset(data, select=c('fttrump1', 'ftbiden1', 'ftsanders1', 'ftbuttigieg1','covid1'))
anes_cov <- filter(anes_cov, anes_cov$fttrump1 <= 100, anes_cov$ftbiden1 <= 100, anes_cov$ftsanders1 <= 100, anes_cov$ftbuttigieg1 <= 100)
anes_cov <- gather(anes_cov ,key = "Presidential_candidate", value = "feeling_temperature", c('fttrump1', 'ftbiden1', 'ftsanders1', 'ftbuttigieg1'))
Updated_anes_cov <- anes_cov %>% group_by(covid1, Presidential_candidate) %>% summarise(mean_temp=mean(feeling_temperature))

ggplot(Updated_anes_cov, aes(x = covid1, y = mean_temp, fill = as.factor(covid1))) +
  geom_bar(stat = "identity") +
  facet_wrap( ~ Presidential_candidate, ncol = 1) + 
  scale_fill_discrete(name ="Covid 19", labels = c("Increased a lot", "Increased a moderate amount", "Increased a little", "Kept the same", "Decreased a little", "Decreased a moderate amount", "Decreased a lot")) +
  theme_bw()+ 
  ggtitle("Mean Feeling of Temperature vs Covid 19") +
  xlab("Covid 19") +
  ylab("Mean Feeling of Temperature")

Conclusion: Biden transitioned from increased from a lot to decreased a little. There are not a lot of decreased cases. The graph tapers down from red to blue. Pete has a slight increase in a moderate amount compared to Biden. Again. there is not a lot of decrease. The graph tapers down relatively. Sanders has higher increases compared to Biden and Pete. The graph tapers down with little decrease in amount. Trump has a greater decrease in amount compared to other 3. We also observe an outlier kind decrease in moderate account. Graphs of Sanders and Biden is almost the same. Pete;s graph is very close to Biden and Sanders.