knitr::opts_chunk$set( message = FALSE, warning = FALSE, comment = "#>" )
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.
devtools::install_github("ropengov/rsunlight")
library('rsunlight')
cg_committees(id = 'JSPR')
cg_districts(latitude = 35.778788, longitude = -78.787805)
cg_districts(zip = 27511)
cg_legislators(last_name = 'Reed')
And get their names and Twitter handles
cg_legislators(zip = 77006)
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')
library('ggplot2') dat <- cw_timeseries(phrase = 'climate change') ggplot(dat, aes(day, count)) + geom_line() + theme_grey(base_size=20)
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"))
os_billsearch(terms = 'agriculture', state = 'tx', chamber = 'upper')
os_legislatorsearch(state = 'tx', party = 'democratic', active = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.