4 July 2014

Multi Variable Visualization

  • Multiple Aesthetics
  • Facetting
  • Matrix View
  • Parallel Coordinates
  • Interaction - Linking / Brushing
  • 3d Static
  • 3d Interactive

Multiple Aesthetics

Showing more than two variables using aesthetics

  • Color
  • Shape
  • Size

Fuel Economy Dataset

library(ggplot2)
?mpg
head(mpg)
##   manufacturer model displ year cyl      trans drv cty hwy fl   class
## 1         audi    a4   1.8 1999   4   auto(l5)   f  18  29  p compact
## 2         audi    a4   1.8 1999   4 manual(m5)   f  21  29  p compact
## 3         audi    a4   2.0 2008   4 manual(m6)   f  20  31  p compact
## 4         audi    a4   2.0 2008   4   auto(av)   f  21  30  p compact
## 5         audi    a4   2.8 1999   6   auto(l5)   f  16  26  p compact
## 6         audi    a4   2.8 1999   6 manual(m5)   f  18  26  p compact

Fuel Economy Dataset

str(mpg)
## 'data.frame':    234 obs. of  11 variables:
##  $ manufacturer: Factor w/ 15 levels "audi","chevrolet",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ model       : Factor w/ 38 levels "4runner 4wd",..: 2 2 2 2 2 2 2 3 3 3 ...
##  $ displ       : num  1.8 1.8 2 2 2.8 2.8 3.1 1.8 1.8 2 ...
##  $ year        : int  1999 1999 2008 2008 1999 1999 2008 1999 1999 2008 ...
##  $ cyl         : int  4 4 4 4 6 6 6 4 4 4 ...
##  $ trans       : Factor w/ 10 levels "auto(av)","auto(l3)",..: 4 9 10 1 4 9 1 9 4 10 ...
##  $ drv         : Factor w/ 3 levels "4","f","r": 2 2 2 2 2 2 2 1 1 1 ...
##  $ cty         : int  18 21 20 21 16 18 18 18 16 20 ...
##  $ hwy         : int  29 29 31 30 26 26 27 26 25 28 ...
##  $ fl          : Factor w/ 5 levels "c","d","e","p",..: 4 4 4 4 4 4 4 4 4 4 ...
##  $ class       : Factor w/ 7 levels "2seater","compact",..: 2 2 2 2 2 2 2 2 2 2 ...

Scatterplot - Categorical vs. Continuous

ggplot(mpg, aes(class, hwy)) + geom_point()

plot of chunk mpg-scatter-cat

Scatterplot - Reorder

ggplot(mpg, aes(reorder(class, hwy), hwy)) + geom_point()

plot of chunk mpg-scatter-cat-reorder

Scatterplot - Reorder based on max

ggplot(mpg, aes(reorder(class, hwy, max), hwy)) + geom_point()

plot of chunk mpg-scatter-cat-reorder-max

Scatterplot - Add a smooth curve

ggplot(mpg, aes(reorder(class, hwy), hwy)) + geom_point() +
  geom_smooth(aes(group = 1), method = loess)

plot of chunk mpg-scatter-cat-smooth

Basic Scatterplot - Continuous vs Continuous

ggplot(mpg, aes(displ, hwy)) + geom_point()

plot of chunk mpg-scatter

Add variable: Color - Discrete

ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point()