Created
June 5, 2019 19:39
-
-
Save arvi1000/6403102bee189439041b3eef4f36bd2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
# Prep data | |
# data from https://poll.qu.edu/texas/release-detail?ReleaseID=2625 | |
dat <- | |
"challenger, d_pct, trump_pct | |
Biden, 48, 44 | |
Sanders, 44, 47 | |
Warren, 45, 46 | |
Harris, 43, 47 | |
Buttigieg, 44, 46 | |
O'Rourke, 45, 48 | |
Castro, 43, 46" %>% | |
read_csv | |
margin_err <- 3.4 | |
dat <- dat %>% | |
mutate(delta = d_pct - trump_pct, | |
range_hi = delta + margin_err, | |
range_low = delta - margin_err) | |
# per https://en.wikipedia.org/wiki/2016_United_States_presidential_election_in_Texas | |
hillary_margin_2016 <- 43.24 - 52.23 | |
# Plot | |
ggplot(dat, aes(x=fct_reorder(challenger, -delta))) + | |
geom_point(aes(y=delta), | |
color='dodgerblue') + | |
geom_linerange(aes(ymin=range_low, ymax=range_hi), | |
color='dodgerblue', size=1) + | |
geom_hline(yintercept = 0) + | |
geom_hline(yintercept = hillary_margin_2016, | |
linetype = 'dotted', color='dodgerblue') + | |
annotate('text', | |
x = 0.5, y = hillary_margin_2016, | |
hjust=0, vjust = -1, | |
size=3, color='dodgerblue', | |
fontface = 'italic', | |
label = paste0('Hillary-Trump popular vote margin 2016: ', | |
round(hillary_margin_2016, 1), '%') | |
) + | |
labs(title = 'Texas Voter Preference', | |
subtitle = paste0('Challenger lead over Trump w/ margin of error', | |
'\nQunnipiac Poll, Jun 5 \'19'), | |
x = 'challenger', y = '(% for challenger) - (% for Trump)', | |
caption = paste('Question: If the election for president', | |
'were being held today, and the candidates were\n', | |
'{challenger} the Democrat and Donald Trump', | |
'the Republican, for whom would you vote?')) + | |
theme_light() + | |
theme(plot.caption = element_text(face='italic', color='grey30'), | |
axis.title = element_text(color='grey70', size = 9)) |
Author
arvi1000
commented
Jun 5, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment