Created
February 13, 2017 22:04
-
-
Save crsh/718f60aaa7e1c45d652806933e47184a to your computer and use it in GitHub Desktop.
Plot control of both chambers of the legislature and the governor
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
library("dplyr") | |
library("tidyr") | |
library("likert") | |
library("papaja") | |
dat <- data.frame( | |
Year = factor(seq(2009, 2017, 2)) | |
, Democrats = c(17, 11, 12, 7, 6) | |
, Mixed = c(24, 17, 14, 20, 19) | |
, Republicans = c(9, 22, 24, 23, 25) | |
) | |
likert_dat <- gather(dat, key = group, value = count, Democrats:Republicans) | |
likert_dat <- do.call( | |
"rbind" | |
, apply(likert_dat, 1, function(x) data.frame(Year = x["Year"], Vote = rep(x["group"], x["count"]))) | |
) | |
likert_dat$Year <- factor(likert_dat$Year, levels = rev(levels(dat$Year))) | |
likert_dat <- likert( | |
data.frame("Number of votes" = likert_dat[, "Vote"]) | |
, grouping = likert_dat[, "Year"] | |
) | |
likert.bar.plot( | |
likert_dat | |
, low.color = "#232066" | |
, high.color = "#E91D0E" | |
) + | |
guides(fill = guide_legend(title = "")) + | |
theme_apa() + | |
theme( | |
strip.text = element_blank() | |
, axis.ticks.y = element_blank() | |
, axis.line.x = element_line() | |
, legend.position = "top" | |
, legend.key.height = unit(12, "points") | |
, legend.key.width = unit(12, "points") | |
) |
Author
crsh
commented
Feb 13, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment