Introduction to the voteogram package

Bob Rudis

2018-09-16

Basic usage only requires this package and ggplot2:

library(voteogram)
library(ggplot2)

Getting Vote Data

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:

str(sen)
#> List of 29
#>  $ vote_id              : chr "S_115_1_110"
#>  $ chamber              : chr "Senate"
#>  $ year                 : int 2017
#>  $ congress             : chr "115"
#>  $ session              : chr "1"
#>  $ roll_call            : int 110
#>  $ needed_to_pass       : int 51
#>  $ date_of_vote         : chr "April  6, 2017"
#>  $ time_of_vote         : chr "12:35 PM"
#>  $ result               : chr "Cloture Motion Agreed to"
#>  $ vote_type            : chr "1/2"
#>  $ question             : chr "On the Cloture Motion"
#>  $ description          : chr "Neil M. Gorsuch, of Colorado, to be an Associate Justice of the Supreme Court of the United States"
#>  $ nyt_title            : chr "On the Cloture Motion"
#>  $ total_yes            : int 55
#>  $ total_no             : int 45
#>  $ total_not_voting     : int 0
#>  $ gop_yes              : int 52
#>  $ gop_no               : int 0
#>  $ gop_not_voting       : int 0
#>  $ dem_yes              : int 3
#>  $ dem_no               : int 43
#>  $ dem_not_voting       : int 0
#>  $ ind_yes              : int 0
#>  $ ind_no               : int 2
#>  $ ind_not_voting       : int 0
#>  $ dem_majority_position: chr "No"
#>  $ gop_majority_position: chr "Yes"
#>  $ votes                :Classes 'tbl_df', 'tbl' and 'data.frame':   100 obs. of  11 variables:
#>   ..$ bioguide_id         : chr [1:100] "A000360" "B001230" "B001261" "B001267" ...
#>   ..$ role_id             : int [1:100] 526 481 498 561 535 547 507 551 480 555 ...
#>   ..$ member_name         : chr [1:100] "Lamar  Alexander" "Tammy Baldwin" "John Barrasso" "Michael Bennet" ...
#>   ..$ sort_name           : chr [1:100] "Alexander" "Baldwin" "Barrasso" "Bennet" ...
#>   ..$ party               : chr [1:100] "R" "D" "R" "D" ...
#>   ..$ state_abbrev        : chr [1:100] "TN" "WI" "WY" "CO" ...
#>   ..$ display_state_abbrev: chr [1:100] "Tenn." "Wis." "Wyo." "Colo." ...
#>   ..$ district            : chr [1:100] "2" "1" "1" "1" ...
#>   ..$ position            : chr [1:100] "Yes" "No" "Yes" "No" ...
#>   ..$ dw_nominate         : logi [1:100] NA NA NA NA NA NA ...
#>   ..$ pp_id               : chr [1:100] "TN" "WI" "WY" "CO" ...
#>  - attr(*, "class")= chr [1:2] "pprc" "list"

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>
str(rep)
#> List of 29
#>  $ vote_id              : chr "H_115_1_256"
#>  $ chamber              : chr "House"
#>  $ year                 : int 2017
#>  $ congress             : chr "115"
#>  $ session              : chr "1"
#>  $ roll_call            : int 256
#>  $ needed_to_pass       : int 216
#>  $ date_of_vote         : chr "May  4, 2017"
#>  $ time_of_vote         : chr "02:18 PM"
#>  $ result               : chr "Passed"
#>  $ vote_type            : chr "RECORDED VOTE"
#>  $ question             : chr "On Passage"
#>  $ description          : chr "American Health Care Act"
#>  $ nyt_title            : chr "On Passage"
#>  $ total_yes            : int 217
#>  $ total_no             : int 213
#>  $ total_not_voting     : int 1
#>  $ gop_yes              : int 217
#>  $ gop_no               : int 20
#>  $ gop_not_voting       : int 1
#>  $ dem_yes              : int 0
#>  $ dem_no               : int 193
#>  $ dem_not_voting       : int 0
#>  $ ind_yes              : int 0
#>  $ ind_no               : int 0
#>  $ ind_not_voting       : int 0
#>  $ dem_majority_position: chr "No"
#>  $ gop_majority_position: chr "Yes"
#>  $ votes                :Classes 'tbl_df', 'tbl' and 'data.frame':   435 obs. of  11 variables:
#>   ..$ bioguide_id         : chr [1:435] "A000374" "A000370" "A000055" "A000371" ...
#>   ..$ role_id             : int [1:435] 274 294 224 427 268 131 388 320 590 206 ...
#>   ..$ member_name         : chr [1:435] "Ralph Abraham" "Alma  Adams" "Robert B. Aderholt" "Pete Aguilar" ...
#>   ..$ sort_name           : chr [1:435] "Abraham" "Adams" "Aderholt" "Aguilar" ...
#>   ..$ party               : chr [1:435] "R" "D" "R" "D" ...
#>   ..$ state_abbrev        : chr [1:435] "LA" "NC" "AL" "CA" ...
#>   ..$ display_state_abbrev: chr [1:435] "La." "N.C." "Ala." "Calif." ...
#>   ..$ district            : int [1:435] 5 12 4 31 12 3 2 19 36 2 ...
#>   ..$ position            : chr [1:435] "Yes" "No" "Yes" "No" ...
#>   ..$ dw_nominate         : logi [1:435] NA NA NA NA NA NA ...
#>   ..$ pp_id               : chr [1:435] "LA_5" "NC_12" "AL_4" "CA_31" ...
#>  - attr(*, "class")= chr [1:2] "pprc" "list"

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.

Making Cartograms

These cartograms have a few style options:

ProPublica

GovTrack

They can be shrunk down well (though that likely means annotating them in some other way):

Tiny Cartograms