Created
October 26, 2021 18:22
-
-
Save sysilviakim/7e657595918c86033e1d9857e87b91c3 to your computer and use it in GitHub Desktop.
Figures created for 656 class
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(dplyr) | |
library(ggplot2) | |
library(ggridges) | |
library(Kmisc) | |
# Brookings Party Unity Votes ================================================== | |
url <- | |
"https://www.brookings.edu/wp-content/uploads/2017/01/vitalstats_ch8_tbl3.csv" | |
df <- read.csv(url) | |
p <- ggplot( | |
df, | |
aes( | |
x = Year, y = PctPartyUnityVotes, | |
group = Chamber, colour = Chamber, linetype = Chamber | |
) | |
) + | |
geom_line() + | |
scale_x_continuous(breaks = seq(1950, 2021, by = 5)) + | |
scale_color_viridis_d(end = 0.75, direction = -1) + | |
theme_bw() | |
pdf("party_unity_votes_congress.pdf", width = 5, height = 4) | |
pdf_default(p) + | |
theme(legend.position = "bottom") | |
dev.off() | |
# DW-NOMINATE Separation ======================================================= | |
url <- "https://voteview.com/static/data/out/members/HSall_members.csv" | |
df <- read.csv(url) | |
congress <- df %>% | |
filter( | |
congress >= 87 & chamber != "President" & | |
district_code != 0 & district_code != 98 & district_code != 99 | |
) %>% | |
filter(party_code == 100 | party_code == 200) %>% | |
arrange(desc(congress)) %>% | |
mutate(year1 = congress * 2 + 1787) %>% | |
arrange(year1) | |
house <- congress %>% filter(chamber == "House") | |
senate <- congress %>% filter(chamber == "Senate") | |
p <- ggplot( | |
house, | |
aes( | |
x = nominate_dim1, y = year1, group = interaction(year1, party_code), | |
fill = factor(party_code) | |
) | |
) + | |
geom_density_ridges( | |
scale = 7, size = 0.25, rel_min_height = 0.01, alpha = 0.5 | |
) + | |
theme_ridges(center = TRUE) + | |
scale_x_continuous( | |
limits = c(-1, 1.3), expand = c(0.01, 0), | |
breaks = c(-1, -.75, -.5, -.25, 0, .25, .5, .75, 1) | |
) + | |
scale_y_reverse(breaks = c(seq(2021, 1961, -10))) + | |
scale_fill_manual( | |
values = c("blue", "red"), breaks = c("100", "200"), | |
labels = c("Democratic", "Republican"), name = "Party" | |
) + | |
ggtitle("DW-NOMINATE by Party of U.S. House: 1961-2021") + | |
ylab("First Year of Each Congress") + | |
xlab("Distribution of 1st Dimension DW-NOMINATE by Party") | |
pdf("dwnom_house_1961_2021.pdf", width = 6, height = 4.5) | |
pdf_default(p) + | |
theme(legend.position = "bottom") | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment