The OpenData movement has the White House producing and releasing some novel datasets.
One of them is the We The People petition site. I learned about this from Proofreader.com’s interesting python work using that data. From the petition site, you
can see an interesting gallery of work done in different language and for different media/platform. One such example is yoni’s r pkg.
In the spirit of the open data goodness, I thought I’d play around as well with this d3 chord diagram.
Read on to make your own!
.chord_plot iframe {
position: absolute;
top:0;
left: 0;
width: 100%;
height: 100%;
}
Downloading data from github repo
if (!require("pacman")) install.packages("pacman")
pacman::p_load_current_gh("mattflor/chorddiag")
pacman::p_load(dplyr, magrittr, ggplot2, tidyr, curl)
So proofreader’s site has a csv, but I found yoni’s pkg most useful because it had scraped the API for more data both in terms of rows and columns. If you wanna hit that API now, download yoni’s package. It’s supposed to have functions for connecting to the API, but I didn’t try it.
curl::curl_download(
"https://github.com/yoni/r_we_the_people/blob/master/data/petition_analyses.RData?raw=true"
, destfile="~/Desktop/petition_analyses.RData"
)
load("~/Desktop/petition_analyses.RData")
p
So I found myself that download.file
was a bit glitchy (trying to download the github website instead of the raw data), so curl::curl_download
was my go-to, probably will be from now on. Make sure to use the link to the raw data (as I did) in your curl call, using the ?raw=true
at end of url.
One thing
I don’t like about load()
on an RData file is that you can’t change the dataframe name to something shorter without creating a new dataframe, which I called p
to save on typing. (If you know how, hit me a suggestion at @data_steve) with the hashtag #aliasForR.
Cleaning / Set up
There’s been some really nice work nice work in visualizing data with d3 and
exposing those tools through APIs for …read more
Source:: r-bloggers.com