- Multiple Aesthetics
- Facetting
- Matrix View
- Parallel Coordinates
- Interaction - Linking / Brushing
- 3d Static
- 3d Interactive
4 July 2014
Showing more than two variables using aesthetics
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
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 ...
ggplot(mpg, aes(class, hwy)) + geom_point()
ggplot(mpg, aes(reorder(class, hwy), hwy)) + geom_point()
ggplot(mpg, aes(reorder(class, hwy, max), hwy)) + geom_point()
ggplot(mpg, aes(reorder(class, hwy), hwy)) + geom_point() + geom_smooth(aes(group = 1), method = loess)
ggplot(mpg, aes(displ, hwy)) + geom_point()
ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point()
ggplot(mpg, aes(displ, hwy, colour = cyl)) + geom_point()
ggplot(mpg, aes(displ, hwy, size = drv)) + geom_point()
ggplot(mpg, aes(displ, hwy, size = cyl)) + geom_point()
ggplot(mpg, aes(displ, hwy, shape = drv)) + geom_point()
ggplot(mpg, aes(displ, hwy, color = class, shape = drv)) + geom_point()
facet_grid
2d grid, rows ~ cols, . for no split
facet_wrap
1d ribbon wrapped into 2d
ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_wrap(~ cyl)
ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_grid(. ~ cyl)
ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_grid(drv ~ .)
ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_grid(drv ~ cyl)
library(GGally) mpg_select <- subset(mpg, select = c(displ, hwy, drv))
ggpairs(mpg_select)
ggpairs(mpg_select, diag = list(continuous = "bar", discrete = "bar"), axisLabels = 'show')
ggpairs(mpg_select, diag = list(continuous = "bar", discrete = "bar"), upper = list(continuous = "density", combo = "dot"), axisLabels = 'show')
ggparcoord(mpg, column = c(1:11), groupColumn = 4)
write.csv(mpg, file = "mpg.csv", quote = FALSE, row.names = FALSE)
library(scatterplot3d) scatterplot3d(mpg$displ, mpg$cyl, mpg$hwy, highlight.3d = TRUE)
library(rgl) # plot3d(mpg$displ, mpg$hwy, mpg$cyl, type = "p", col = "red")
Amit Kapoor
Partner, narrativeVIZ Consulting
You can find this presentation and more at: