Minard and Tufte Work in R

This document will display example plots derived from: http://motioninsocial.com/tufte/#introduction.

It also serves as an example of R Markdown.


Load packages:

library(ggplot2)
library(ggthemes)
library(devtools)
## Loading required package: usethis
library(epanetReader)
library(reshape)
library(RCurl)
source_url("https://raw.githubusercontent.com/sjmurdoch/fancyaxis/master/fancyaxis.R")
## SHA-1 hash of file is 1eaf278aced5a1206f1c0bffab087d26f44e3f73

1. Marginal histogram scatter plot

base graphics with fancyaxis

x <- faithful$waiting
y <- faithful$eruptions
plot(x, y, main="", axes=FALSE, pch=16, cex=0.8,
     xlab="Time till next eruption (min)", ylab="Duration (sec)", 
     xlim=c(min(x)/1.1, max(x)), ylim=c(min(y)/1.5, max(y)))
axis(1, tick=F)
axis(2, tick=F, las=2)
axisstripchart(faithful$waiting, 1)
axisstripchart(faithful$eruptions, 2)


2. Dot-dash plot

ggplot2

ggplot(mtcars, aes(wt, mpg)) + geom_point() + geom_rug() + theme_tufte(ticks=F) + 
  xlab("Car weight (lb/1000)") + ylab("Miles per gallon of fuel") + 
  theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1))


3. Sparklines

base R with plotSparklineTable

dd <- read.csv(text = getURL("https://gist.githubusercontent.com/GeekOnAcid/da022affd36310c96cd4/raw/9c2ac2b033979fcf14a8d9b2e3e390a4bcc6f0e3/us_nr_of_crimes_1960_2014.csv"))
d <- melt(dd[,c(2:11)])
## Using  as id variables
plotSparklineTable(d, row.var = 'variable', col.vars = 'value')