Question 1

Our data comes from fivethirtyeight’s Trump Congress tracker. Download and read in (read_csv) the data.


library(tidyverse)
## ── Attaching packages ───────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2     ✓ purrr   0.3.4
## ✓ tibble  3.0.3     ✓ dplyr   1.0.2
## ✓ tidyr   1.1.1     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.5.0
## ── Conflicts ──────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
# again, my path (on website) may be different than yours 
congress<-read_csv("../data/congress-trump-score.csv") 
## Parsed with column specification:
## cols(
##   congress = col_double(),
##   chamber = col_character(),
##   bioguide = col_character(),
##   last_name = col_character(),
##   state = col_character(),
##   district = col_double(),
##   party = col_character(),
##   votes = col_double(),
##   agree_pct = col_double(),
##   predicted_agree = col_double(),
##   net_trump_vote = col_double()
## )

Question 2

Look at the data with glimpse().


congress %>%
  glimpse()
## Rows: 1,735
## Columns: 11
## $ congress        <dbl> 0, 115, 116, 0, 115, 116, 0, 115, 116, 0, 115, 116, 0…
## $ chamber         <chr> "house", "house", "house", "house", "house", "house",…
## $ bioguide        <chr> "A000055", "A000055", "A000055", "A000367", "A000367"…
## $ last_name       <chr> "Aderholt", "Aderholt", "Aderholt", "Amash", "Amash",…
## $ state           <chr> "AL", "AL", "AL", "MI", "MI", "MI", "NV", "NV", "NV",…
## $ district        <dbl> 4, 4, 4, 3, 3, 3, 2, 2, 2, 12, 12, 12, 31, 31, 31, 12…
## $ party           <chr> "Republican", "R", "R", "Independent", "R", "I", "Rep…
## $ votes           <dbl> 141, 95, 46, 140, 96, 44, 140, 94, 46, 138, 92, 46, 1…
## $ agree_pct       <dbl> 0.97872340, 0.96842105, 1.00000000, 0.62142857, 0.541…
## $ predicted_agree <dbl> 0.95556332, 0.94634916, 0.97459258, 0.77280357, 0.847…
## $ net_trump_vote  <dbl> 63.0, 63.0, 63.0, 9.4, 9.4, 9.4, 12.3, 12.3, 12.3, -4…

Question 3

We want to see how does the percentage that a member of Congress’ agrees with President Trump (agree_pct) depend on the result of the 2016 Presidential election in their district (net_trump_vote)? First, plot a scatterplot of agree_pct on net_trump_vote. Add a regression line with an additional layer of geom_smooth(method="lm").


scatter<-ggplot(data = congress)+
  aes(x = net_trump_vote, y=agree_pct)+
  geom_point()+
  geom_smooth(method="lm")+
  theme_light()
scatter
## `geom_smooth()` using formula 'y ~ x'