install.packages("tidyverse")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)
install.packages("dplyr")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)
install.packages("ggplot2")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
library(ggplot2)
anes_full <- read_csv("anes_timeseries_cdf_csv_20220916.csv")
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
## Rows: 68224 Columns: 1030
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr    (3): Version, VCF0900c, VCF0901b
## dbl (1019): VCF0004, VCF0006, VCF0006a, VCF0009x, VCF0010x, VCF0011x, VCF000...
## lgl    (8): VCF0391c, VCF0391d, VCF1030a, VCF1030b, VCF1031a, VCF1031b, VCF1...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
anes_po <- data.frame(anes_full$VCF0004, anes_full$VCF0218, anes_full$VCF0224, anes_full$VCF0302)
anes_po <- na.omit(anes_po)
anes_po <- subset(anes_po, anes_po$anes_full.VCF0302 <= 2 | anes_po$anes_full.VCF0302 == 5)
anes_po <- rename(anes_po, Year = anes_full.VCF0004, dem_feelings = anes_full.VCF0218, repub_feelings = anes_full.VCF0224, Party = anes_full.VCF0302)
anes_po$Party <- recode(anes_po$Party, "1" = "R", "5" = "D")
## Warning: Unreplaced values treated as NA as `.x` is not compatible.
## Please specify replacements exhaustively or supply `.default`.
anes_po <- anes_po %>%
  group_by(Year, Party) %>%
  summarise(mean_dem_feel = mean(dem_feelings), mean_repub_feel = mean(repub_feelings))
## `summarise()` has grouped output by 'Year'. You can override using the
## `.groups` argument.
anes_po_dr <- subset(anes_po, anes_po$Party == "D" | anes_po$Party == "R")
ggplot(anes_po_dr, aes(x=Year, color=Party)) +
  geom_line(aes(y=mean_repub_feel)) +
  geom_line(aes(y=mean_dem_feel)) +
  scale_color_manual(values = c("blue", "red")) +
  ylab("Party Feelings Thermometers") +
  ggtitle("How Partisans Feel About the Two Parties") +
  theme_minimal() +
  annotate("text", x=1986, y=65, label="How partisans feel about their own party", color="black", size=3) +
  annotate("text", x=2013.5, y=40, label="How partisans feel about the other party", color="black", size = 3)

ggplot(anes_po, aes(x=Year, color=Party)) +
  geom_line(aes(y=mean_repub_feel)) +
  theme_minimal() +
  scale_color_manual(values=c("blue", "purple", "red")) +
  ylab("Republican Feelings Thermometer") +
  ggtitle("How People Feel About Republicans")

ggplot(anes_po, aes(x=Year, color=Party)) +
  geom_line(aes(y=mean_dem_feel)) +
  theme_minimal() +
  scale_color_manual(values=c("blue", "purple", "red")) +
  ylab("Democrat Feelings Thermometer") +
  ggtitle("How People Feel About Democrats")