knitr::opts_chunk$set(fig.retina=2)
U.S. House and Senate Voting Cartogram Generators
'ProPublica' https://projects.propublica.org/represent/ makes United States Congress member votes available and has developed their own unique cartogram to visually represent this data as has 'GovTrack'
Ref: (these are replicated below)
You can grab the results of a roll call vote (House or Senate) with roll_call()
. It returns a list
with a ton of information that you can use outside this package. One
element of that list is the data.frame
of vote results. You can pass in the entire
object to either _carto()
function and it'll "fortify" it before shunting it off
to ggplot2. Try to cache this data (I do, below, in R markdown chunk) as you're ticking credits off of ProPublica's monthly free S3 allotment each call. Consider donating to them if you're too lazy to cache the data).
voteogram
themeggparliament
since GT only has the seat view for the Senate)htmlwidget
versionThe following functions are implemented:
house_carto
: Produce a ProPublica- or GovTrack-style House roll call vote cartogramsenate_carto
: Produce a Senate cartogramroll_call
: Get Voting Record for House or Senate By Number, Session & Roll Call NumberHelpers:
theme_voteogram
: voteogram ggplot2 themeprint.pprc
: Better default 'print' function for roll_call()
(pprc
) objectsfortify.pprc
: In case you want to use the voting data frame from a roll_call()
(pprc
) object in your own plots and forget to just $votes
it out. #helpingvoteogram
remotes::install_github("hrbrmstr/voteogram")
options(width=120)
library(voteogram) library(hrbrthemes) library(ggplot2) # current verison packageVersion("voteogram")
sen <- roll_call("senate", 115, 1, 110) rep <- roll_call("house", 115, 1, 256)
str(sen) sen$votes
str(rep) fortify(rep)
senate_carto(sen) + labs(title="Senate Vote 110 - Invokes Cloture on Neil Gorsuch Nomination") + theme_ipsum_rc(plot_title_size = 24) + theme_voteogram()
house_carto(rep, pp_square=TRUE) + labs(x=NULL, y=NULL, title="House Vote 256 - Passes American Health Care Act,\nRepealing Obamacare") + theme_ipsum_rc(plot_title_size = 24) + theme_voteogram()
house_carto(rep, pp_square=FALSE) + labs(x=NULL, y=NULL, title="House Vote 256 - Passes American Health Care Act,\nRepealing Obamacare") + theme_ipsum_rc(plot_title_size = 24) + theme_voteogram()
house_carto(rep, "gt") + labs(x=NULL, y=NULL, title="House Vote 256 - Passes American Health Care Act,\nRepealing Obamacare") + theme_ipsum_rc(plot_title_size = 24) + theme_voteogram()
They can be shrunk down well (though that means annotating them in some other way):
senate_carto(sen) + theme_voteogram(legend=FALSE)
house_carto(rep) + theme_voteogram(legend=FALSE)
house_carto(rep, pp_square=TRUE) + theme_voteogram(legend=FALSE)
library(voteogram) library(testthat) date() test_dir("tests/")
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.