For this worksheet, we need the following packages:

library(tidyverse)
library(socviz)

2012 Election Vote Share

gss_vote_share <-  gss_sm |>
  select(polviews, sex, obama) |>
  drop_na(polviews) |>
  group_by(sex, polviews) |>
  summarize(count = sum(obama, na.rm = T)) |>
  mutate(prop = count / sum(count))

ggplot(gss_vote_share, mapping = aes(x = prop, y = polviews, fill = sex)) +
  geom_col() + facet_wrap(~ sex) +
  guides(fill = "none") +
  labs(title = "Political views and voting in the 2012 election",
       subtitle = "Obama's vote share among men and women",
       x = NULL, y = "Political views",
       caption = "Source: GSS") +
  scale_x_continuous(labels = scales::percent) +
  theme_minimal()