Types of charts
The Grammar of Graphics
Examples
“The grammar of graphics determines how algebra, geometry, aesthetics, statistics, scales and coordinates interact”
Operations applied before scale transformations
sin
, log
)Let \(A := (x,y,z)\) and \(B := (a,a,b)\)
Cross, \(A\times B\) \[ = ([x,y],~[y,a],~[z,b]) \]
Nest, \(A/B\)
\[ = (x|a,~y|a,~z|b) \]
Blend, \(A+B\) \[ = (x,y,z,a,a,b) \]
“Graphics do not care about the scales on which they are drawn”
After scale & variable transformations
Before coordinate transformations
Things we can actually see
Functions | Partitions | Networks |
---|---|---|
point line area interval path schema |
contour polygon |
edge |
Collision modifiers: stack, dodge, jitter
“Ordinary graphics such as intervals and polygons take on radically different appearances under different planar transformations.”
A new graphic? Or a transformation of an existing one?
Form | Surface | Motion | Sound | Text |
---|---|---|---|---|
position size shape rotation resolution |
colour texture blur transparency |
direction speed acceleration |
tone volume rhythm voice |
label |
“Much of the skill in graphic design is knowing what combinations of attributes to avoid.”
Titanic
dataset
head(Titanic)
## Class Sex Age Survived Freq
## 1 1st Male Child No 0
## 2 2nd Male Child No 0
## 3 3rd Male Child No 35
## 4 Crew Male Child No 0
## 5 1st Female Child No 0
## 6 2nd Female Child No 0
Algebra: Class
× Survived
× Freq
pie <- ggplot(Titanic) +
scale_x_discrete() + scale_y_continuous() + scale_fill_discrete() +
geom_bar(width = 1, position = "fill") +
aes(x = "", fill = Survived, weight = Freq) +
theme_titanic()
pie <- pie + coord_polar(theta = "y")
pie <- pie + facet_grid(. ~ Class)
gg <- ggplot(troops, aes(x = long, y = lat))
gg <- gg + geom_path(aes(size = survivors,
colour = direction,
group = group), lineend = "round")
gg <- gg + geom_text(data = cities, aes(label = city),
size = 3, family = "serif", fontface = "italic")
Graphics Production Language (SPSS)
ggplot2 / ggvis (R)
Bokeh (Python)
Gadfly (Julia)
D3 / Vega (JavaScript)
Grammarphone (Spotify API)
source('asciiplot.R')
asciiplot(df = iris,
aes = list(x='Sepal.Width', y='Sepal.Length'),
geom = 'point')
## O
## O O O O
## O
## O
## O O O O
## O
## O O
## O O O
## O O O O O
## O O O
## O O O O O O O O O
## O O O O
## O O O O O O O
## O O
## O O O O O O O O O
## O O O O O
## O O O O O O O O O O
## O
## O O O O O O O O
## O O O O O O O O O O O
## O O O
## O
## O O O O O
## O O O
## O
Implements a sound geom
for line graphs
Maps values in data to frequency/volume of music
Awarded 1st prize at Anvil Hack II
Definitely useful
Wilkinson, Leland. The Grammar of Graphics. 2nd edition. Springer Science & Business Media, 2005.
Wickham, Hadley. “A layered grammar of graphics.” Journal of Computational and Graphical Statistics 19.1 (2010): 3–28.
Source code available on Github