Wisconsin Districts

district_elect <- fec16::results_house |>
  select(-runoff_votes, -runoff_percent, -footnotes) |>
  mutate(district = parse_number(district_id)) |>
  group_by(state, district) |>
  summarize(
    N = n(), 
    total_votes = sum(general_votes, na.rm = TRUE),
    d_votes = sum(ifelse(party == "DEM", general_votes, 0), na.rm = TRUE),
    r_votes = sum(ifelse(party == "REP", general_votes, 0), na.rm = TRUE),
    .groups = "drop"
  ) |>
  mutate(
    other_votes = total_votes - d_votes - r_votes,
    r_prop = r_votes / total_votes,  
    winner = ifelse(r_votes > d_votes, "Republican", "Democrat")
  )
wi_results <- district_elect |>
  filter(state == "WI")

wi_d3 <- fec16::results_house |>
  select(-runoff_votes, -runoff_percent, -footnotes) |>
  filter(state == "WI") |>
  filter(district_id == "03")

wi_d3
# A tibble: 2 × 10
  state district_id cand_id   incumbent party primary_votes primary_percent
  <chr> <chr>       <chr>     <lgl>     <chr>         <dbl>           <dbl>
1 WI    03          H6WI03099 TRUE      DEM           33320           0.812
2 WI    03          H6WI03164 FALSE     DEM            7689           0.187
# ℹ 3 more variables: general_votes <dbl>, general_percent <dbl>, won <lgl>

Wisconsin District 3 had 2 democrats running for the house seat.

src <- "http://cdmaps.polisci.ucla.edu/shp/districts113.zip"
lcl_zip <- fs::path(tempdir(), "districts113.zip")
download.file(src, destfile = lcl_zip)
lcl_districts <- fs::path(tempdir(), "districts113")
unzip(lcl_zip, exdir = lcl_districts)
dsn_districts <- fs::path(lcl_districts, "districtShapes")

districts <- st_read(dsn_districts, layer = "districts113") |>
  mutate(DISTRICT = parse_number(as.character(DISTRICT)))
Reading layer `districts113' from data source 
  `/tmp/Rtmp1ix7SY/districts113/districtShapes' using driver `ESRI Shapefile'
Simple feature collection with 436 features and 15 fields (with 1 geometry empty)
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -179.1473 ymin: 18.91383 xmax: 179.7785 ymax: 71.35256
Geodetic CRS:  NAD83
wi_shp <- districts |>
  filter(STATENAME == "Wisconsin")
wi_merged <- wi_shp |>
  st_transform(4326) |>
  inner_join(wi_results, by = c("DISTRICT" = "district"))

wi <- ggplot(data = wi_merged, aes(fill = winner)) +
  annotation_map_tile(zoom = 6, type = "osm", progress = "none") + 
  geom_sf(alpha = 0.5) +
  scale_fill_manual("Winner", values = c("blue", "red")) + 
  geom_sf_label(aes(label = DISTRICT)) + 
  ggtitle("Wisconsin House Winners by District") +
  labs(x = element_blank(), y = element_blank())+
  dark_theme_gray(base_size = 12) + 
  theme(
        axis.ticks = element_blank(), 
        axis.text = element_blank(), 
        plot.margin = unit(c(0.2, 0.7, 0, 1.5), "cm"))

wi

wi_results |>                  
  select(-state)
# A tibble: 8 × 8
  district     N total_votes d_votes r_votes other_votes r_prop winner    
     <dbl> <int>       <dbl>   <dbl>   <dbl>       <dbl>  <dbl> <chr>     
1        1     7      353990  107003  230072       16915  0.650 Republican
2        2     2      397581  273537  124044           0  0.312 Democrat  
3        3     2      257401  257401       0           0  0     Democrat  
4        4     4      285858  220181       0       65677  0     Democrat  
5        5     3      390507  114477  260706       15324  0.668 Republican
6        6     4      356935  133072  204147       19716  0.572 Republican
7        7     4      362061  138643  223418           0  0.617 Republican
8        8     4      363574  135682  227892           0  0.627 Republican

The map shows the winners of the 2016 House elections in Wisconsin. The district shapes are very irregular. District 4 is extremely small when compared to district 7. There are 2 districts where there isn’t even a republican running. The races where republicans have won the district, they have won by a small margin. However, the margin is not as small as the North Carolina districts that we looked at in class.