Skip to content

Instantly share code, notes, and snippets.

@dgrtwo
Created November 5, 2020 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgrtwo/5399fb08459276a64c8878ddfe193a42 to your computer and use it in GitHub Desktop.
Save dgrtwo/5399fb08459276a64c8878ddfe193a42 to your computer and use it in GitHub Desktop.
# Data copied from a PDF https://drive.google.com/file/d/1JirsgRrAfSX43Vt1-b-dubKat_AofWvl/view
pa <- read_delim("county ballots d_margin D R potential_net
STATEWIDE 581694 75% 436087 145610 290477
ADAMS 250 61% 153 97 56
ALLEGHENY 35806 80% 28645 7161 21484
ARMSTRONG 5380 57% 3067 2313 754
BEAVER 24688 70% 17282 7406 9876
BEDFORD 0 41% 0 0 0
BERKS 3714 73% 2711 1003 1708
BLAIR 17232 61% 10512 6720 3792
BRADFORD 468 59% 276 192 84
BUCKS 47095 77% 36263 10832 25431
BUTLER 32967 64% 21099 11868 9231
CAMBRIA 440 62% 273 167 106
CAMERON 0 49% 0 0 0
CARBON 5672 59% 3346 2326 1020
CENTRE 4514 78% 3521 993 2528
CHESTER 41817 79% 33035 8782 24253
CLARION 2023 57% 1153 870 283
CLEARFIELD 795 57% 453 342 111
CLINTON 23 64% 15 8 7
COLUMBIA 8478 57% 4832 3646 1186
CRAWFORD 10923 54% 5898 5025 873
CUMBERLAND 31970 73% 23338 8632 14706
DAUPHIN 1052 78% 821 231 590
DELAWARE 11849 85% 10072 1777 8295
ELK 117 57% 67 50 17
ERIE 16980 77% 13075 3905 9170
FAYETTE 793 67% 531 262 269
FOREST 18 57% 10 8 2
FRANKLIN 11129 61% 6789 4340 2449
FULTON 44 42% 18 26 -8
GREENE 4382 55% 2410 1972 438
HUNTINGDON 40 59% 24 16 8
INDIANA -13 63% -8 -5 -3
JEFFERSON 141 52% 73 68 5
JUNIATA 2375 42% 998 1377 -379
LACKAWANNA 878 78% 685 193 492
LANCASTER 19592 70% 13714 5878 7836
LAWRENCE 703 65% 457 246 211
LEBANON 2483 64% 1589 894 695
LEHIGH 39072 79% 30867 8205 22662
LUZERNE 20194 68% 13732 6462 7270
LYCOMING 345 62% 214 131 83
MCKEAN 1357 58% 787 570 217
MERCER 12226 66% 8069 4157 3912
MIFFLIN 638 55% 351 287 64
MONROE 14381 75% 10786 3595 7191
MONTGOMERY 2792 83% 2317 475 1842
MONTOUR 50 66% 33 17 16
NORTHAMPTON 1647 73% 1202 445 757
NORTHUMBERLAND 162 62% 100 62 38
PERRY 564 57% 321 243 78
PHILADELPHIA 104607 93% 97285 7322 89963
PIKE 29 65% 19 10 9
POTTER 43 50% 22 21 1
SCHUYLKILL 279 60% 167 112 55
SNYDER 141 59% 83 58 25
SOMERSET 565 52% 294 271 23
SULLIVAN 55 54% 30 25 5
SUSQUEHANNA 104 59% 61 43 18
TIOGA 4593 40% 1837 2756 -919
UNION 161 70% 113 48 65
VENANGO 6435 60% 3861 2574 1287
WARREN 362 61% 221 141 80
WASHINGTON 951 69% 656 295 361
WAYNE 193 62% 120 73 47
WESTMORELAND 20978 67% 14055 6923 7132
WYOMING 61 61% 37 24 13
YORK 1894 66% 1250 644 606", delim = " ") %>%
mutate(d_margin = parse_number(d_margin) * .01) %>%
mutate(county = str_to_title(county)) %>%
filter(county != "Statewide") %>%
filter(ballots > 0) # Indiana county has -13, hrm
library(dplyr)
library(ggplot2)
library(tidyr)
library(scales)
# Colors are 538 palette
pa %>%
gather(party, value, D, R) %>%
mutate(county = fct_lump(county, 40, w = ballots)) %>%
mutate(county = fct_reorder(county, value, sum)) %>%
group_by(county, party) %>%
summarize(value = sum(value)) %>%
mutate(value = ifelse(party == "R", -value, value)) %>%
ggplot(aes(value, county, fill = party)) +
geom_col() +
scale_x_continuous(labels = comma_format()) +
scale_fill_manual(values = c("#30a2da", "#fc4f30")) +
labs(y = "",
x = "Expected # of mail ballots remaining",
fill = "Party",
title = "How would we estimate remaining ballots will go in Pennsylvania?",
subtitle = "Biden needs to make up a deficit of 115,000 votes")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment