This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(plyr) | |
| library(ggplot2) | |
| s <- read.csv("<filename.csv>", sep=",", row.names=NULL) | |
| colnames(s) <- c("date", "type", "desc", "value", "balance", "acc") | |
| s$date <- as.Date(s$date, format="%d/%m/%Y") | |
| s <- s[,1:5] | |
| s$month <- as.Date(cut(s$date, breaks="month")) | |
| s <- subset(s, s$value < 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require(ggplot2) | |
| lm_eqn <- function(m) { | |
| # fromm: http://stackoverflow.com/a/13451587/1274516 | |
| l <- list(a = format(coef(m)[1], digits = 2), | |
| b = format(abs(coef(m)[2]), digits = 2), | |
| r2 = format(summary(m)$r.squared, digits = 3)); | |
| if (coef(m)[2] >= 0) { | |
| eq <- substitute(italic(y) == a + b %.% italic(x)*","~~italic(r)^2~"="~r2,l) | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require("zoo") | |
| require("ggplot2") | |
| # unemployment | |
| u <- read.csv("Employment.csv", header=T) | |
| u <- melt(u, "Year") | |
| unemployment <- data.frame(date=as.yearmon(do.call(paste, u[,1:2]), "%Y %b"), | |
| rate=u$value) | |
| unemployment <- unemployment[unemployment$date > as.yearmon("2008-12"),] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library("jsonlite") | |
| library("stringr") | |
| oauth <- scan("yourOAuth.token", "character") | |
| getCMD <- function(user){ | |
| # crude system command for querying Github API | |
| newcmd <- paste0("curl -H 'Accept: application/vnd.github.v3.text-match+json Authorization: token ", | |
| oauth, "' 'https://api.github.com/search/code?q=set.seed+in:file+language:R+user:", | |
| user,"&page=1&per_page=500' | grep 'fragment' -") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library("ggplot2") | |
| library("scales") | |
| ## Data: http://www.theguardian.com/news/datablog/2009/oct/21/icm-poll-data-labour-conservatives#data (State of the parties spreadsheet) | |
| # ICM poll resultsof ~1000 people taken every month or so | |
| # (more often before an election) as well as election | |
| # results dating from June 1984. | |
| sop <- read.csv("StateOfTheParties.csv", stringsAsFactors=F) | |
| ## Data cleanup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| options(PlosApiKey = "<insert your API key here!>") | |
| #install_github("rplos", "ropensci") | |
| library("rplos") | |
| library("ggplot2") | |
| require("dplyr") | |
| # Convert author strings to counts | |
| countAuths <- function(cell) | |
| length(unlist(strsplit(cell, ";"))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library("RCurl") | |
| library("jsonlite") | |
| library("ggplot2") | |
| library("RColorBrewer") | |
| library("scales") | |
| library("gridExtra") | |
| api.key <- "yourAPIkey" | |
| rt <- getURI(paste0("http://api.rottentomatoes.com/api/public/v1.0/lists/dvds/top_rentals.json?apikey=", api.key, "&limit=50")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype HTML> | |
| <meta charset = 'utf-8'> | |
| <html> | |
| <head> | |
| <script src='http://d3js.org/d3.v3.min.js' type='text/javascript'></script> | |
| <script src='http://dimplejs.org/dist/dimple.v1.1.1.min.js' type='text/javascript'></script> | |
| <style> | |
| .rChart { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype HTML> | |
| <meta charset = 'utf-8'> | |
| <html> | |
| <head> | |
| <script src='http://d3js.org/d3.v3.min.js' type='text/javascript'></script> | |
| <script src='http://dimplejs.org/dist/dimple.v1.1.1.min.js' type='text/javascript'></script> | |
| <style> | |
| .rChart { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype HTML> | |
| <meta charset = 'utf-8'> | |
| <html> | |
| <head> | |
| <link rel='stylesheet' href='http://nvd3.org/assets/css/nv.d3.css'> | |
| <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js' type='text/javascript'></script> | |
| <script src='http://d3js.org/d3.v3.min.js' type='text/javascript'></script> | |
| <script src='http://timelyportfolio.github.io/rCharts_nvd3_tests/libraries/widgets/nvd3/js/nv.d3.min-new.js' type='text/javascript'></script> | |
| <script src='http://nvd3.org/assets/lib/fisheye.js' type='text/javascript'></script> |
OlderNewer