Skip to content

Instantly share code, notes, and snippets.

@ozjimbob
Created February 2, 2016 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozjimbob/b0fc0927e6c05ce8d0e6 to your computer and use it in GitHub Desktop.
Save ozjimbob/b0fc0927e6c05ce8d0e6 to your computer and use it in GitHub Desktop.
R Dem Iowa Caucus Graph
library(rjson)
library(httr)
turl="https://iowadems-caucussitecdn-prod2.azureedge.net/api/statecandidateresults"
a=GET(turl)
arr=c(content(a)$StateResults[[1]]$WinPercentage,content(a)$StateResults[[2]]$WinPercentage,content(a)$StateResults[[3]]$WinPercentage)
nam=c(content(a)$StateResults[[1]]$Candidate$DisplayName,content(a)$StateResults[[2]]$Candidate$DisplayName,content(a)$StateResults[[3]]$Candidate$DisplayName)
colr=c(content(a)$StateResults[[1]]$Candidate$Color,content(a)$StateResults[[2]]$Candidate$Color,content(a)$StateResults[[3]]$Candidate$Color)
rar=round(arr,3)*100
barplot(arr,names.arg=nam,col=colr)
text(1:3,0.3,rar,cex=2,pos=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment