Created
March 16, 2017 15:39
-
-
Save chrishanretty/f3b0eb0594d4dd3d989080f1867f9b1a to your computer and use it in GitHub Desktop.
Plot ENEP across time, parliamentary democracies
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
## Requires data from ParlGov | |
elex <- read.csv("view_election.csv") | |
elex <- subset(elex, election_type %in% "parliament") | |
elex <- subset(elex, country_name_short != "TUR") | |
aux <- read.csv("viewcalc_election_parameter.csv") | |
dat <- merge(unique(elex[,c("election_id", "country_name_short", "election_date")]), aux, all.x = T, all.y = F) | |
dat <- dat[order(-dat$enp_votes),] | |
dat[1:30,c("country_name_short", "election_date", "enp_votes","enp_seats")] | |
dat$election_date <- as.Date(dat$election_date) | |
dat$group <- "All parliamentary elections" | |
first_wave <- c("DNK", "AUS", "NZL", "BEL", "CAN", "SWE", "CHE", | |
"NOR", "ISL", "IRL", "FIN", "FRA", "NLD", "JPN", | |
"GBR", "LUX", "AUT", "ISR", "ITA", "DEU", "MLT") | |
second_wave <- c("GRC", "PRT", "ESP", "TUR", "CYP") | |
third_wave <- c("HRV", "EST", "HUN", "ROU", "BGR", "CZE", "LTU", "LVA", "SVN", "SVK", "POL") | |
dat$group[dat$country_name_short %in% first_wave] <- "Pre-1960 democracies" | |
dat$group[dat$country_name_short %in% second_wave] <- "Post-1960 democracies" | |
dat$group[dat$country_name_short %in% third_wave] <- "Post-1989 democracies" | |
### Now do a plot | |
library(ggplot2) | |
library(ggrepel) | |
nld <- data.frame(country_name_short = "NLD", | |
election_date = as.Date("2017-03-15"), | |
enp_votes = 8.5814811636, | |
label = "NLD17", | |
group = "Pre-1960 democracies") | |
dat$label <- paste0(dat$country_name_short, format(dat$election_date, "%y")) | |
p1 <- ggplot(subset(dat, election_date > as.Date("1946-01-01")), | |
aes(x = election_date, y = enp_votes, group = country_name_short, colour = group)) + | |
geom_point(alpha = 0.5) + | |
geom_point(data = nld, color = "black") + | |
geom_smooth(se = FALSE, aes(group = group, colour = group)) + | |
# annotate(geom = "text", x = nld$election_date, y = nld$enp_votes, label = "NLD17", hjust = 1) + | |
geom_text_repel(data = subset(dat, enp_votes > 8), aes(label = label)) + | |
geom_text_repel(data = nld, aes(label = label), alpha = 1, size = 6) + | |
scale_x_date("Election date") + | |
scale_y_continuous("Effective number of parties (vote share)") + | |
scale_color_discrete("Grouping") + | |
theme_bw() + | |
guides(label = "none", alpha = "none") + | |
theme(legend.position = "bottom", legend.box = "horizontal") | |
png(file = "waves.png", width = 800, height = 600) | |
p1 | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment