Step 2: analysis

This notebook reads the clean data and makes every table and figure. It does no cleaning and drops no one. If the sample needs to change, change clean_data.qmd and run both again.

# packages
library(tidyverse)
library(here)

# read the clean data made by clean_data.qmd
survey = read_csv(here("data", "clean", "clean_data.csv"))

The analysis uses 4815 respondents. Overall, 39.2 percent of them support the border wall.

Support by party

# share who support the wall within each party, and how many people that is
by_party = survey |>
  group_by(party) |>
  summarize(respondents = n(),
            percent_support = round(mean(support_wall) * 100, 1))

# save the table, then show it
write_csv(by_party, here("tables", "wall_by_party.csv"))

knitr::kable(by_party, col.names = c("Party", "Respondents", "Support the wall (%)"))
Table 1: Support for the border wall, by party. Percents are out of each party’s respondents.
Party Respondents Support the wall (%)
Democrat 2413 9.7
Independent 732 39.3
Republican 1670 81.7

Support by party and education

# put education in order, from least to most schooling
educ_order = c("No HS", "High school graduate", "Some college",
               "2-year", "4-year", "Post-grad")

by_party_educ = survey |>
  mutate(educ = factor(educ, levels = educ_order)) |>
  group_by(party, educ) |>
  summarize(respondents = n(),
            percent_support = mean(support_wall) * 100)

ggplot(by_party_educ, aes(x = educ, y = percent_support, color = party, group = party)) +
  geom_line() +
  geom_point(aes(size = respondents)) +
  scale_color_manual(values = c("Democrat" = "#355B85",
                                "Independent" = "grey50",
                                "Republican" = "#C8413B")) +
  labs(x = NULL, y = "Support the wall (%)", color = NULL, size = "Respondents") +
  theme_minimal()

# save the figure
ggsave(here("figures", "wall_by_party_educ.png"), width = 8, height = 5)
Figure 1: Support for the border wall, by party and education.