% Ben Bolker
% Wed Nov 7 12:01:58 2012

Data visualization, focusing on ggplot and mixed models

cc
Licensed under the
Creative Commons attribution-noncommercial license.
Please share & remix noncommercially, mentioning its origin.

goals/contexts of data visualization

exploration

diagnostics

presentation

Basic criteria for data presentation

challenges

high-dimensional data (esp continuous)

Solutions:

large data sets

discrete data

spatial data

compositional data

next generation tools

Data visualization in R

Base graphics

Lattice

ggplot

ggplot intro

mappings + geoms

Data

Specified explicitly as part of a ggplot call:

library(mlmRev)
head(Oxboys)
##   Subject     age height Occasion
## 1       1 -1.0000  140.5        1
## 2       1 -0.7479  143.4        2
## 3       1 -0.4630  144.8        3
## 4       1 -0.1643  147.1        4
## 5       1 -0.0027  147.7        5
## 6       1  0.2466  150.2        6
library(ggplot2)
ggplot(Oxboys)
## Error: No layers in plot

But that isn't quite enough: we need to specify a mapping between variables (columns in the data set) and aesthetics (elements of the graphical display: x-location, y-location, colour, size, shape …)

ggplot(Oxboys, aes(x = age, y = height))
## Error: No layers in plot

but (as you can see) that's still not quite enough. We need to specify some geometric objects (called geoms) such as points, lines, etc., that will embody these aesthetics. The weirdest thing about ggplot syntax is that these geoms get added to the existing ggplot object that specifies the data and aesthetics; unless you explicitly specify other aesthetics, they are inherited from the initial ggplot call.

ggplot(Oxboys, aes(x = age, y = height)) + geom_point()

plot of chunk ggplot3