<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/voteogram-is-now-on-cran/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://rud.is/b/2017/11/27/voteogram-is-now-on-cran/"> R – rud.is</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Earlier this year, I made a package that riffed off of ProPublica’s really neat voting cartograms (maps) for the U.S. House and Senate. You can see one for disaster relief spending <a rel="nofollow" href="https://projects.propublica.org/represent/votes/115/house/1/566" target="_blank">in the House</a> and one for the ACA “Skinny Repeal” <a rel="nofollow" href="https://projects.propublica.org/represent/votes/115/senate/1/179" target="_blank">in the Senate</a>.</p>
<p>We can replicate both here with the <code>voteogram</code> package (minus the interactivity, for now):</p>
<pre><code>library(voteogram)
library(ggplot2)

hr_566 &lt;- roll_call(critter=&quot;house&quot;, number=115, session=1, rcall=566)

house_carto(hr_566) +
  coord_equal() +
  theme_voteogram()</code></pre>
<p><a rel="nofollow" href="https://i1.wp.com/rud.is/b/wp-content/uploads/2017/11/Plot_Zoom.png?ssl=1" target="_blank"><img alt="" src="https://i1.wp.com/rud.is/b/wp-content/uploads/2017/11/Plot_Zoom.png?resize=378%2C215&ssl=1" class="wp-image-7270" data-recalc-dims="1"></a></p>
<pre><code>sen_179 &lt;- roll_call(critter=&quot;senate&quot;, number=115, session=1, rcall=179)

senate_carto(sen_179) +
  coord_equal() +
  theme_voteogram()</code></pre>
<p><a rel="nofollow" href="https://i2.wp.com/rud.is/b/wp-content/uploads/2017/11/plot_zoom_png-4.png?ssl=1" target="_blank"><img alt="" src="https://i2.wp.com/rud.is/b/wp-content/uploads/2017/11/plot_zoom_png-4.png?resize=397%2C249&ssl=1" class="wp-image-7271" data-recalc-dims="1"></a></p>
<p>I think folks might have more fun with the <code>roll_call()</code> objects though:</p>
<pre><code>str(hr_566)
## List of 29
##  $ vote_id              : chr &quot;H_115_1_566&quot;
##  $ chamber              : chr &quot;House&quot;
##  $ year                 : int 2017
##  $ congress             : chr &quot;115&quot;
##  $ session              : chr &quot;1&quot;
##  $ roll_call            : int 566
##  $ needed_to_pass       : int 282
##  $ date_of_vote         : chr &quot;October 12, 2017&quot;
##  $ time_of_vote         : chr &quot;03:23 PM&quot;
##  $ result               : chr &quot;Passed&quot;
##  $ vote_type            : chr &quot;2/3 YEA-AND-NAY&quot;
##  $ question             : chr &quot;On Motion to Suspend the Rules and Agree&quot;
##  $ description          : chr &quot;Providing for the concurrence by the House in the Senate amendment to H.R. ## 2266, with an amendment&quot;
##  $ nyt_title            : chr &quot;On Motion to Suspend the Rules and Agree&quot;
##  $ total_yes            : int 353
##  $ total_no             : int 69
##  $ total_not_voting     : int 11
##  $ gop_yes              : int 164
##  $ gop_no               : int 69
##  $ gop_not_voting       : int 7
##  $ dem_yes              : int 189
##  $ dem_no               : int 0
##  $ dem_not_voting       : int 5
##  $ ind_yes              : int 0
##  $ ind_no               : int 0
##  $ ind_not_voting       : int 0
##  $ dem_majority_position: chr &quot;Yes&quot;
##  $ gop_majority_position: chr &quot;Yes&quot;
##  $ votes                :Classes ‘tbl_df’, ‘tbl’ and 'data.frame':  435 obs. of  11 variables:
##   ..$ bioguide_id         : chr [1:435] &quot;A000374&quot; &quot;A000370&quot; &quot;A000055&quot; &quot;A000371&quot; ...
##   ..$ role_id             : int [1:435] 274 294 224 427 268 131 388 320 590 206 ...
##   ..$ member_name         : chr [1:435] &quot;Ralph Abraham&quot; &quot;Alma Adams&quot; &quot;Robert B. Aderholt&quot; &quot;Pete Aguilar&quot; ...
##   ..$ sort_name           : chr [1:435] &quot;Abraham&quot; &quot;Adams&quot; &quot;Aderholt&quot; &quot;Aguilar&quot; ...
##   ..$ party               : chr [1:435] &quot;R&quot; &quot;D&quot; &quot;R&quot; &quot;D&quot; ...
##   ..$ state_abbrev        : chr [1:435] &quot;LA&quot; &quot;NC&quot; &quot;AL&quot; &quot;CA&quot; ...
##   ..$ display_state_abbrev: chr [1:435] &quot;La.&quot; &quot;N.C.&quot; &quot;Ala.&quot; &quot;Calif.&quot; ...
##   ..$ district            : int [1:435] 5 12 4 31 12 3 2 19 36 2 ...
##   ..$ position            : chr [1:435] &quot;Yes&quot; &quot;Yes&quot; &quot;Yes&quot; &quot;Yes&quot; ...
##   ..$ dw_nominate         : num [1:435] 0.493 -0.462 0.36 -0.273 0.614 0.684 0.388 NA 0.716 NA ...
##   ..$ pp_id               : chr [1:435] &quot;LA_5&quot; &quot;NC_12&quot; &quot;AL_4&quot; &quot;CA_31&quot; ...
##  - attr(*, &quot;class&quot;)= chr [1:2] &quot;pprc&quot; &quot;list&quot;</code></pre>
<p>as they hold tons of info on the votes.</p>
<p>I need to explore the following a bit more but there are some definite “patterns” in the way the 115th Senate has voted this year:</p>
<pre><code>library(hrbrthemes)

# I made a mistake in how I exposed these that I'll correct next month
# but we need to munge it a bit anyway for this view
fills &lt;- voteogram:::vote_carto_fill
names(fills) &lt;- tolower(names(fills))

rcalls &lt;- map(1:280, ~voteogram::roll_call(critter=&quot;senate&quot;, session=1, number=115, rcall=.x))
# save it off so you don't have to waste those calls again
write_rds(rcalls, &quot;2017-115-1-sen-280-roll-calls.rds&quot;)

# do a bit of wrangling
map_df(rcalls, ~{
  mutate(.x$votes, vote_id = .x$vote_id) %>% 
    arrange(party, position) %>% 
    mutate(fill = tolower(sprintf(&quot;%s-%s&quot;, party, position))) %>% 
    mutate(ques = .x$question) %>% 
    mutate(x = 1:n())
}) -> votes_df

# plot it
ggplot(votes_df, aes(x=x, y=vote_id, fill=fill)) +
  geom_tile() +
  scale_x_discrete(expand=c(0,0)) +
  scale_y_discrete(expand=c(0,0)) +
  scale_fill_manual(name=NULL, values=fills) +
  labs(x=NULL, y=NULL, title=&quot;Senate Roll Call Votes&quot;,
       subtitle=&quot;2017 / 115th, Session 1, Votes 1-280&quot;,
       caption=&quot;Note free-Y scales&quot;) +
  facet_wrap(~ques, scales=&quot;free_y&quot;, ncol=3) +
  theme_ipsum_rc(grid=&quot;&quot;) +
  theme(axis.text = element_blank()) +
  theme(legend.position=&quot;right&quot;)</code></pre>
<p><a rel="nofollow" href="https://i0.wp.com/rud.is/b/wp-content/uploads/2017/11/plot_zoom_png-1-2.png?ssl=1" target="_blank"><img alt="" src="https://i0.wp.com/rud.is/b/wp-content/uploads/2017/11/plot_zoom_png-1-2.png?resize=780%2C880&ssl=1" class="wp-image-7272" data-recalc-dims="1"></a></p>
<p>Hopefully I’ll get some time to dig into the differences and report on anything interesting. If you get to it before me definitely link to your blog post in a comment!</p>
<h3>FIN</h3>
<p>I still want to make an <code>htmlwidgets</code> version of the plots and also add the ability to get the index of roll call votes by Congress number and session to make it easier to iterate.</p>
<p>I’m also seriously considering creating different palettes. I used the ones from the source interactive site but am not 100% happy with them. Suggestions/PRs welcome.</p>
<p>Hopefully this package will make it easier for U.S. folks to track what’s going on in Congress and keep their representatives more accountable to the truth.</p>
<p>Everything’s on <a rel="nofollow" href="https://github.com/hrbrmstr/voteogram" target="_blank">GitHub</a> so please file issues, questions or PRs there.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://rud.is/b/2017/11/27/voteogram-is-now-on-cran/"> R – rud.is</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/c0Y2qYpP3B8" height="1"></a></div>