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)
Their structures look the same and there is a print-method to make the console output easier on the eyes:
sen
#> 115th Congress / Session: 1 / Senate Roll Call: 110 / April 6, 2017
#>
#> Neil M. Gorsuch, of Colorado, to be an Associate Justice of the Supreme Court of the United States
#>
#> Result: Cloture Motion Agreed to
sen$votes
#> # A tibble: 100 x 11
#> bioguide_id role_id member_name sort_name party state_abbrev
#> * <chr> <int> <chr> <chr> <chr> <chr>
#> 1 A000360 526 Lamar Alexander Alexander R TN
#> 2 B001230 481 Tammy Baldwin Baldwin D WI
#> 3 B001261 498 John Barrasso Barrasso R WY
#> 4 B001267 561 Michael Bennet Bennet D CO
#> 5 B001277 535 Richard Blumenthal Blumenthal D CT
#> 6 B000575 547 Roy Blunt Blunt R MO
#> 7 B001288 507 Cory Booker Booker D NJ
#> 8 B001236 551 John Boozman Boozman R AR
#> 9 B000944 480 Sherrod Brown Brown D OH
#> 10 B001135 555 Richard M. Burr Burr R NC
#> # ... with 90 more rows, and 5 more variables: display_state_abbrev <chr>,
#> # district <chr>, position <chr>, dw_nominate <lgl>, pp_id <chr>
rep
#> 115th Congress / Session: 1 / House Roll Call: 256 / May 4, 2017
#>
#> American Health Care Act
#>
#> Result: Passed
fortify(rep)
#> # A tibble: 435 x 11
#> bioguide_id role_id member_name sort_name party state_abbrev
#> * <chr> <int> <chr> <chr> <chr> <chr>
#> 1 A000374 274 Ralph Abraham Abraham R LA
#> 2 A000370 294 Alma Adams Adams D NC
#> 3 A000055 224 Robert B. Aderholt Aderholt R AL
#> 4 A000371 427 Pete Aguilar Aguilar D CA
#> 5 A000372 268 Rick Allen Allen R GA
#> 6 A000367 131 Justin Amash Amash R MI
#> 7 A000369 388 Mark Amodei Amodei R NV
#> 8 A000375 320 Jodey Arrington Arrington R TX
#> 9 B001291 590 Brian Babin Babin R TX
#> 10 B001298 206 Don Bacon Bacon R NE
#> # ... with 425 more rows, and 5 more variables:
#> # display_state_abbrev <chr>, district <int>, position <chr>,
#> # dw_nominate <lgl>, pp_id <chr>
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)