Last active
July 22, 2019 03:56
-
-
Save wmurphyrd/a20e0bb47ffdc2a3618f01858055bff8 to your computer and use it in GitHub Desktop.
2020 Candidate Climate Leadership Scores
This file contains hidden or 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
Name | Party | State | Public Engagement | Press Releases | Bills Sponsored | Bills Cosponsored | Caucuses | Website | Total | Senator | 2020 Hopeful | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Whitehouse, Sheldon | D | RI | 30 | 7 | 7 | 7 | 10 | 10 | 71 | Whitehouse, Sheldon (D-RI) | No | |
Schatz, Brian | D | HI | 24 | 5 | 14 | 8 | 4 | 10 | 65 | Schatz, Brian (D-HI) | No | |
Markey, Ed | D | MA | 20 | 8 | 11 | 6 | 10 | 10 | 65 | Markey, Ed (D-MA) | No | |
Sanders, Bernie | I | VT | 17 | 7 | 15 | 4 | 10 | 10 | 63 | Sanders, Bernie (I-VT) | Yes | |
Boxer, Barbara | D | CA | 22 | 4 | 6 | 4 | 10 | 10 | 56 | Boxer, Barbara (D-CA) | No | |
Cardin, Ben | D | MD | 20 | 6 | 0 | 1 | 10 | 10 | 47 | Cardin, Ben (D-MD) | No | |
King, Angus | I | ME | 25 | 6 | 0 | 1 | 10 | 5 | 47 | King, Angus (I-ME) | No | |
Cantwell, Maria | D | WA | 19 | 5 | 0 | 3 | 10 | 10 | 47 | Cantwell, Maria (D-WA) | No | |
Menendez, Robert | D | NJ | 17 | 4 | 0 | 5 | 10 | 10 | 46 | Menendez, Robert (D-NJ) | No | |
Merkley, Jeff | D | OR | 10 | 4 | 6 | 5 | 10 | 10 | 45 | Merkley, Jeff (D-OR) | Yes | |
Booker, Cory | D | NJ | 18 | 4 | 0 | 0 | 10 | 10 | 42 | Booker, Cory (D-NJ) | Yes | |
Feinstein, Dianne | D | CA | 15 | 4 | 6 | 3 | 0 | 10 | 38 | Feinstein, Dianne (D-CA) | No | |
Udall, Tom | D | NM | 12 | 5 | 7 | -1 | 10 | 5 | 38 | Udall, Tom (D-NM) | No | |
Coons, Christopher | D | DE | 14 | 4 | 3 | 6 | 0 | 10 | 37 | Coons, Christopher (D-DE) | No | |
Gillibrand, Kirsten | D | NY | 10 | 4 | 1 | 0 | 10 | 10 | 35 | Gillibrand, Kirsten (D-NY) | Yes | |
Shaheen, Jeanne | D | NH | 7 | 5 | 0 | 2 | 10 | 10 | 34 | Shaheen, Jeanne (D-NH) | No | |
Heinrich, Martin | D | NM | 10 | 3 | 0 | -1 | 10 | 10 | 32 | Heinrich, Martin (D-NM) | No | |
Reid, Harry | D | NV | 15 | 5 | 0 | 2 | 0 | 10 | 32 | Reid, Harry (D-NV) | No | |
Murphy, Chris | D | CT | 0 | 5 | 0 | 2 | 10 | 10 | 27 | Murphy, Chris (D-CT) | No | |
Leahy, Patrick | D | VT | 14 | 4 | 0 | 4 | 0 | 5 | 27 | Leahy, Patrick (D-VT) | No | |
Reed, Jack | D | RI | 9 | 2 | 4 | 1 | 0 | 10 | 26 | Reed, Jack (D-RI) | No | |
Nelson, Bill | D | FL | 15 | 2 | 7 | 1 | 0 | 0 | 25 | Nelson, Bill (D-FL) | No | |
Warren, Elizabeth | D | MA | 10 | 2 | 0 | 3 | 10 | 0 | 25 | Warren, Elizabeth (D-MA) | Yes | |
Wyden, Ron | D | OR | 10 | 4 | 4 | 1 | 0 | 5 | 24 | Wyden, Ron (D-OR) | No | |
Carper, Thomas | D | DE | 5 | 2 | 3 | 2 | 0 | 10 | 22 | Carper, Thomas (D-DE) | No | |
Hirono, Maizie | D | HI | 12 | 4 | 0 | 1 | 0 | 5 | 22 | Hirono, Maizie (D-HI) | No | |
Blumenthal, Richard | D | CT | 3 | 2 | 1 | 0 | 10 | 5 | 21 | Blumenthal, Richard (D-CT) | No | |
Schumer, Chuck | D | NY | 14 | 3 | 0 | 4 | 0 | 0 | 21 | Schumer, Chuck (D-NY) | No | |
Mikulski, Barbara | D | MD | 14 | 4 | 0 | 0 | 0 | 0 | 18 | Mikulski, Barbara (D-MD) | No | |
Stabenow, Debbie | D | MI | 7 | 4 | 0 | 2 | 0 | 5 | 18 | Stabenow, Debbie (D-MI) | No | |
Franken, Al | D | MN | 7 | 3 | 0 | 2 | 0 | 5 | 17 | Franken, Al (D-MN) | No | |
Brown, Sherrod | D | OH | 10 | 0 | 0 | 1 | 0 | 5 | 16 | Brown, Sherrod (D-OH) | Yes | |
Klobuchar, Amy | D | MN | -5 | 2 | 1 | 0 | 10 | 5 | 13 | Klobuchar, Amy (D-MN) | Yes | |
Peters, Gary | D | MI | 7 | 4 | 0 | 0 | 0 | 0 | 11 | Peters, Gary (D-MI) | No | |
Bennet, Michael | D | CO | -6 | 4 | 4 | 3 | 0 | 5 | 10 | Bennet, Michael (D-CO) | No | |
Durbin, Richard | D | IL | -5 | 3 | 0 | 2 | 0 | 10 | 10 | Durbin, Richard (D-IL) | No | |
Collins, Susan | R | ME | 0 | 1 | 1 | -1 | 0 | 5 | 6 | Collins, Susan (R-ME) | No | |
Baldwin, Tammy | D | WI | 0 | 4 | 0 | 1 | 0 | 0 | 5 | Baldwin, Tammy (D-WI) | No | |
Kaine, Tim | D | VA | -4 | -1 | 0 | 2 | 0 | 5 | 2 | Kaine, Tim (D-VA) | No | |
Ayotte, Kelly | R | NH | 3 | 1 | 0 | -3 | 0 | 0 | 1 | Ayotte, Kelly (R-NH) | No | |
Grassley, Chuck | R | IA | 0 | -4 | 0 | -4 | 0 | 5 | -3 | Grassley, Chuck (R-IA) | No | |
Casey, Bob | D | PA | -7 | 0 | 0 | 4 | 0 | 0 | -3 | Casey, Bob (D-PA) | No | |
Warner, Mark | D | VA | -7 | -3 | 4 | -1 | 0 | 0 | -7 | Warner, Mark (D-VA) | No | |
Tester, Jon | D | MT | -10 | -2 | 0 | -4 | 0 | 0 | -16 | Tester, Jon (D-MT) | No | |
Donnelly, Joe | D | IN | -10 | -2 | 0 | 0 | 0 | -5 | -17 | Donnelly, Joe (D-IN) | No | |
Heitkamp, Heidi | D | ND | -20 | -5 | 6 | 0 | 1 | -5 | -23 | Heitkamp, Heidi (D-ND) | No | |
Manchin, Joe | D | WV | -17 | -6 | 0 | 2 | 0 | -5 | -26 | Manchin, Joe (D-WV) | No | |
McCaskill, Claire | D | MO | -20 | -3 | -4 | -2 | 0 | 0 | -29 | McCaskill, Claire (D-MO) | No |
This file contains hidden or 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
--- | |
title: "R Notebook" | |
output: | |
html_document: | |
df_print: paged | |
--- | |
```{r setup} | |
library(tidyverse) | |
library(plotly) | |
library(ggrepel) | |
dat <- read_csv("Climate Hawks Vote 2015 Scores.csv") | |
``` | |
```{r} | |
dat %>% | |
select_if(is.numeric) %>% | |
as.matrix %>% | |
cov %>% | |
as.data.frame() %>% | |
rownames_to_column("var1") %>% | |
gather(var2, value, -var1) %>% | |
mutate(type = ifelse(var1 == var2, "var", "cov")) -> | |
varcov | |
varcov %>% | |
arrange(type, desc(value)) | |
``` | |
Component with most variance: Public Engagement | |
```{r} | |
varcov %>% | |
filter(var1 == "Public Engagement", type == "cov") %>% | |
arrange(value) | |
``` | |
High variance components least correlated with public engagment: caucuses | |
```{r} | |
dat %>% | |
ggplot(aes(y = `Public Engagement`, x = Caucuses)) + | |
geom_point() | |
``` | |
Despite high vairance, Caucses is nearly dichotomous. Probbaly better to bin and place on a qualitative mapping. | |
```{r} | |
dat %>% | |
ggplot(aes(y = `Public Engagement`, x = `Bills Cosponsored`)) + | |
geom_point() | |
``` | |
```{r} | |
dat %>% | |
ggplot(aes(y = `Public Engagement`, x = `Bills Sponsored`)) + | |
geom_point() | |
``` | |
Public Engagement versus Bills **Co**sponsored gives the most varied distribution - will use these for the positional mappings. | |
```{r} | |
bgc <- "#111111" | |
bg <- element_rect(color = bgc, fill = bgc) | |
dat2 <- dat %>% | |
mutate(Caucuses =`levels<-`( | |
Hmisc::cut2(Caucuses, c(0, 1, 10, 11)), | |
c("None", "Some", "All") | |
)) | |
base_plot <- dat2 %>% | |
ggplot(aes(y = `Public Engagement`, x = `Bills Cosponsored`, | |
label = Name)) + | |
geom_point(aes(color = Website, size = `Bills Sponsored`, | |
shape = Caucuses), | |
# position = position_jitter(0.1, 0.1, 100), | |
fill = "grey80", stroke = 1.5) + | |
scale_shape_manual("Caucus\nMembership", values = c(1, 21, 19)) + | |
scale_color_gradientn("Website Score", | |
colors = RColorBrewer::brewer.pal(5, "RdYlBu"), | |
limits = c(-10, 10)) + | |
labs( | |
x = "Bill Cosponsorship Score", y = "Public Engagement Score", | |
title = "Climate Leadership Scores", | |
subtitle = "for potential 2020 Democratic candidates", | |
caption = "data from Climate Hawks Vote 2015 Senate scorecards" | |
) + | |
theme( | |
panel.background = bg, | |
text = element_text(color = "white"), | |
plot.background = bg, | |
legend.background = bg, | |
legend.key = bg, | |
panel.grid = element_blank(), | |
legend.margin = margin(0, 0, 0, 0), | |
axis.text = element_text(color = "white"), | |
axis.ticks = element_line(color = "white") | |
) | |
static_plot <- base_plot + | |
geom_label_repel(data = filter(dat, `2020 Hopeful` == "Yes"), | |
# position = position_jitter(0.1, 0.1, 100), | |
hjust = 1.15, vjust = "middle", alpha = 0.9, | |
segment.color = "grey80", | |
direction="y", seed = 100) + | |
scale_size("Bill Sponsorship Score", limits = c(-5, 15), | |
breaks = c(-5, 5, 15)) + | |
guides( | |
shape = guide_legend( | |
override.aes = list(color = c("#ffffbf"), size = 4) | |
), | |
size = guide_legend( | |
override.aes = list(color = c("#ffffbf")) | |
) | |
) + | |
theme(text = element_text(size = 16, color = "white")) | |
static_plot | |
``` | |
```{r} | |
size <- 5 | |
ggsave("climate scores.png", static_plot, height = size, width = size * 1.618) | |
``` | |
```{r} | |
# fix legend label being placed incorrectly - remove and add manually | |
interactive_plot <- plotly::ggplotly(base_plot + | |
guides(size = guide_legend(""), | |
shape = guide_legend(""))) %>% | |
add_annotations(text="Caucus\nMembership", | |
xref="paper", yref="paper", | |
x=1.03, xanchor="left", | |
y=0.35, yanchor="bottom", | |
legendtitle=TRUE, showarrow=FALSE) | |
# remove excess padding | |
interactive_plot$sizingPolicy$padding <- "0" | |
# highlight 2020 contenders | |
# (can't use data index because data is split by symbol) | |
c2020 <- dat$Name[dat$`2020 Hopeful` == "Yes"] %>% | |
paste(collapse = "|") | |
interactive_plot$x$data <- lapply(interactive_plot$x$data, function (trc) { | |
if (length(trc$text) == 0) { return(trc) } | |
sel <- grep(c2020, trc$text) | |
trc$selectedpoints <- sel - 1 # zero-based js indexing | |
trc | |
}) | |
htmlwidgets::saveWidget( | |
interactive_plot, "index.html", libdir = "lib", | |
title = "2020 Candidate Climate Leadership Scores", | |
selfcontained = FALSE, background = bgc | |
) | |
interactive_plot | |
``` | |
Abandoned concepts and other scratch work below: | |
```{r} | |
rank_order <- dat$Name[order(dat$Total)] | |
dat %>% | |
ggplot(aes(y = `Public Engagement`, x = Name, | |
color = `2020 Hopeful`)) + | |
geom_point() + | |
scale_x_discrete(limits = rank_order) + | |
coord_flip() | |
``` | |
```{r} | |
table(dat$`Bills Sponsored`) | |
``` | |
```{r} | |
table(dat$`Website`) | |
``` | |
```{r} | |
Hmisc::cut2(dat$Caucuses, c(0, 1, 10, 11)) %>% | |
table | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment