Skip to content

Instantly share code, notes, and snippets.

@crsh
Created February 13, 2017 22:04
Show Gist options
  • Save crsh/718f60aaa7e1c45d652806933e47184a to your computer and use it in GitHub Desktop.
Save crsh/718f60aaa7e1c45d652806933e47184a to your computer and use it in GitHub Desktop.
Plot control of both chambers of the legislature and the governor
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")
)
@crsh
Copy link
Author

crsh commented Feb 13, 2017

state_control

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment