-
-
Save thomasjensen/1507831 to your computer and use it in GitHub Desktop.
first look at voting data from the Danish parliament
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(plyr) | |
library(ggplot2) | |
setwd("/.../") | |
data <- read.csv("ft.csv") | |
data.final <- data[data$Amendment == 0,] | |
data.amendment <- data[data$Amendment == 1,] | |
activity <- ddply(data.final,c("Year","Month"),function(x) data.frame(count = length(unique(x$Voteid)))) | |
out <- expand.grid(seq(2005,2011,1),seq(1,12,1)) | |
out <- merge(out, activity, by.x = c("Var1","Var2"), by.y = c("Year","Month"), all.x = TRUE) | |
out[is.na(out$count),"count"] <- 0 | |
out$date <- as.Date(paste("1-",out$Var2,"-",out$Var1, sep = ""), format = "%d-%m-%Y") | |
plot <- ggplot(out, aes(x = date, y = count)) + | |
geom_line() + | |
geom_vline(xintercept = as.numeric(as.Date(c("13-11-2007","15-09-2011"), format = "%d-%m-%Y")), colour = "red") + | |
theme_bw() | |
plot | |
##degree of unanimity over time | |
agreement.final <- ddply(data.final, c("Year","Month"), function(x) data.frame(agreement = sum(x$Vote.Numeric == 1)/(sum(x$Vote.Numeric == 1) + sum(x$Vote.Numeric == 4)))) | |
agreement.final$date <- as.Date(paste("1-",agreement.final$Month,"-",agreement.final$Year, sep = ""), format = "%d-%m-%Y") | |
plot <- ggplot(agreement.final, aes(x = date, y = agreement)) + | |
geom_line() + | |
geom_vline(xintercept = as.numeric(as.Date(c("13-11-2007","15-09-2011"), format = "%d-%m-%Y")), colour = "red") + | |
scale_y_continuous(limits = c(0,1)) + | |
theme_bw() | |
plot | |
agreement.amendment <- ddply(data.amendment, c("Year","Month"), function(x) data.frame(agreement = sum(x$Vote.Numeric == 1)/(sum(x$Vote.Numeric == 1) + sum(x$Vote.Numeric == 4)))) | |
agreement.amendmemt$date <- as.Date(paste("1-",agreement.amendment$Month,"-",agreement.amendment$Year, sep = ""), format = "%d-%m-%Y") | |
plot <- ggplot(agreement,amendmemt, aes(x = date, y = agreement)) + | |
geom_line() + | |
geom_vline(xintercept = as.numeric(as.Date(c("13-11-2007","15-09-2011"), format = "%d-%m-%Y")), colour = "red") + | |
scale_y_continuous(limits = c(0,1)) + | |
theme_bw() | |
plot | |
agreement.full <- ddply(data, c("Year","Month"), function(x) data.frame(agreement = sum(x$Vote.Numeric == 1)/(sum(x$Vote.Numeric == 1) + sum(x$Vote.Numeric == 4)))) | |
agreement.full$date <- as.Date(paste("1-",agreement.full$Month,"-",agreement.full$Year, sep = ""), format = "%d-%m-%Y") | |
plot <- ggplot(agreement.full, aes(x = date, y = agreement)) + | |
geom_line() + | |
geom_vline(xintercept = as.numeric(as.Date(c("13-11-2007","15-09-2011"), format = "%d-%m-%Y")), colour = "red") + | |
scale_y_continuous(limits = c(0,1)) + | |
theme_bw() | |
plot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment