knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Basic usage only requires this package and ggplot2
:
library(voteogram) library(ggplot2)
The cartograms need data and the best way to do that is by obtaining roll call vote data from ProPublica via the roll_call()
function. Data can be retrieved for any House or Senate vote by specificing the target vote parameters:
sen <- roll_call("senate", 115, 1, 110) rep <- roll_call("house", 115, 1, 256)
sen <- readRDS(system.file("extdata", "sen.rds", package="voteogram")) rep <- readRDS(system.file("extdata", "rep.rds", package="voteogram"))
Their structures look the same and there is a print-method to make the console output easier on the eyes:
str(sen) sen$votes
str(rep) fortify(rep)
That data may be useful on its own (ouside of plotting).
Note, also, that ggplot2
's fortify()
method uses the provided object class method for roll call objects to know how to extract the rectangular data necessary for plotting.
These cartograms have a few style options:
senate_carto(sen) + labs(title="Senate Vote 110 - Invokes Cloture on Neil Gorsuch Nomination") + 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_voteogram()
house_carto(rep, pp_square=FALSE) + labs(x=NULL, y=NULL, title="House Vote 256 - Passes American Health Care Act,\nRepealing Obamacare") + theme_voteogram()
house_carto(rep, "gt") + labs(x=NULL, y=NULL, title="House Vote 256 - Passes American Health Care Act,\nRepealing Obamacare") + theme_voteogram()
They can be shrunk down well (though that likely 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)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.