knitr::opts_chunk$set(
    message = FALSE,
    warning = FALSE,
    comment = "#>"
)

rsunlight vignette - Interface to Sunlight Labs APIs

rsunlight is an R package to search and retrieve data from the Sunlight Labs APIs.

Returned objects from functions are simple lists. That is, you likely will want to take output objects and make data.frames, vectors, matrices, etc. In future versions of rsunlight, I will return data.frame's when possible as those are easy to work with in R for beginners, though advanced users may prefer lists or raw responses from the API with lots of info, including header, etc.

Installation

devtools::install_github("ropengov/rsunlight")
library('rsunlight')

Congress API

Gets details (subcommittees + membership) for a committee by id.

cg_committees(id = 'JSPR')

Get districts for a latitude/longitude.

cg_districts(latitude = 35.778788, longitude = -78.787805)

Get districts that overlap for a certain zip code.

cg_districts(zip = 27511)

Search politicians by name

cg_legislators(last_name = 'Reed')

Search politicians by zip code

And get their names and Twitter handles

cg_legislators(zip = 77006)

Capitol Words API

Popularity of a phrase through time.

Get a list of how many times the phrase "united states" appears in the Congressional Record in each month between January and June, 2010:

cw_timeseries(phrase='united states', start_date='2009-01-01', end_date='2009-04-30', granularity='month')

Plot data

library('ggplot2')
dat <- cw_timeseries(phrase = 'climate change')
ggplot(dat, aes(day, count)) + 
  geom_line() + 
  theme_grey(base_size=20)

Plot more data

dat_d <- cw_timeseries(phrase='climate change', party="D")
dat_d$party <- rep("D", nrow(dat_d))
dat_r <- cw_timeseries(phrase='climate change', party="R")
dat_r$party <- rep("R", nrow(dat_r))
dat_both <- rbind(dat_d, dat_r)
ggplot(dat_both, aes(day, count, colour=party)) + 
  geom_line() + 
  theme_grey(base_size=20) + 
  scale_colour_manual(values=c("blue","red"))

Open States API

Search OpenStates bills.

os_billsearch(terms = 'agriculture', state = 'tx', chamber = 'upper')

Search Legislators on OpenStates

os_legislatorsearch(state = 'tx', party = 'democratic', active = TRUE)


rOpenGov/rsunlight documentation built on July 21, 2019, 3:18 a.m.