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
\documentclass[nohyper,justified]{tufte-handout} | |
%\documentclass{article} | |
%\usepackage[absolute,showboxes]{textpos} | |
\usepackage[absolute]{textpos} | |
\usepackage{sidecap} | |
%\usepackage{color} | |
%\usepackage[usenames,dvipsnames,svgnames,table]{xcolor} | |
\begin{document} | |
<<include=FALSE>>= |
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
\documentclass[nohyper,justified]{tufte-handout} | |
%\documentclass{article} | |
%\usepackage[absolute,showboxes]{textpos} | |
\usepackage[absolute]{textpos} | |
\usepackage{sidecap} | |
%\usepackage{color} | |
%\usepackage[usenames,dvipsnames,svgnames,table]{xcolor} | |
\begin{document} | |
\SweaveOpts{concordance=TRUE} |
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
#copied this function almost entirely from http://tradeblotter.wordpress.com/ | |
#I only take credit for the ugly/bad code | |
#amended to accept data in long form and replace time with manager | |
# Histogram, QQPlot and ECDF plots aligned by scale for comparison | |
page.Distributions.long <- function (R, mgrcol, perfcol, ylim=c(0,0.25)) { | |
require(PerformanceAnalytics) | |
op <- par(no.readonly = TRUE) | |
# c(bottom, left, top, right) | |
par(oma = c(5,0,2,1), mar=c(0,0,0,3)) |
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
##################### | |
# R function for downloading plain-text data from GitHub | |
# Christopher Gandrud | |
# 7 January 2013 | |
##################### | |
# source_GitHubData is directly based on source_url from the Hadley Wickham's devtools package | |
source_GitHubData <-function(url, sep = ",", header = TRUE) | |
{ |
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
rm(list = ls()) | |
doInstall <- TRUE # Change to FALSE if you don't want packages installed. | |
toInstall <- c("zoo", "tm", "ggplot2", "Snowball") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
# From: http://www.cnn.com/2012/10/03/politics/debate-transcript/index.html | |
Transcript <- readLines("https://raw.github.com/dsparks/Test_image/master/Denver_Debate_Transcript.txt") | |
head(Transcript, 20) |
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
# Drawing a scatter plot of raster images | |
doInstall <- TRUE # Change to FALSE if you don't want packages installed. | |
toInstall <- c("png", "sna") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
# Go to https://www.gosquared.com/resources/2400-flags, download the ZIP, | |
# and put the 64 x 64 files into a directory of your choosing. | |
# Then setwd() to that directory: | |
setwd("C:/Dropbox/isDotR_Files/flagIcons") |
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
doInstall <- TRUE | |
toInstall <- c("Amelia", "ggplot2") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
ANES <- read.csv("http://www.oberlin.edu/faculty/cdesante/assets/downloads/ANES.csv") | |
ANES <- ANES[ANES$year == 2008, -c(1, 11, 17)] # Limit to just 2008 respondents, | |
head(ANES) # remove some non-helpful variables | |
with(ANES, plot(jitter(pid7), jitter(ideo7))) |
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(RJSONIO) | |
library(plyr) | |
#racechart | |
#Helper functions | |
getNum=function(x){as.numeric(as.character(x))} | |
timeInS=function(tStr){ | |
x=unlist(strsplit(tStr,':')) | |
tS=60*getNum(x[1])+getNum(x[2]) |
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(MASS) | |
library(lattice) | |
## Plot the claims frequency against age group by engine size and district | |
barchart(Claims/Holders ~ Age | Group, groups=District, | |
data=Insurance, origin=0, auto.key=TRUE) | |
barchart(Claims/Holders ~ Age | Group, groups=District, | |
data=Insurance,main="Claims frequency", | |
auto.key=list(space="top", columns=4, | |
title="District", cex.title=1)) |
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
toInstall <- c("ggplot2") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
library(ggplot2) | |
text.plots <- data.frame( | |
SUPP = c (rep(c( "Control", "Vitamin C", "Orange Juice" ), each = 1500)) , | |
DOSE = rep(rep(c( "I", "II", "III" ), each=500), 3), | |
LENGTH = c(rnorm(500, 4, 2), | |
rnorm(500, 7, 1.2), |