470

# QCBS R workshop - Visualization March 22, 2013

## Transcript

1. Plotting in
Open Source Statistical
Programming
map courtesy of James Cheshire (spatialanalysis.co.uk/2012/02/great-maps-ggplot2/)

2. Tables
Data
Graphs
Statistics
Understanding
Sigmaplot
Excel
SAS
Why do your plotting in R?
Simpler workflow:

3. Tables
Data
Statistics
Understanding
Graphs
Why do your plotting in R?
Simpler workflow:

4. Why do your plotting in R?
Flexible and beautiful graphics:

5. Why do your plotting in R?
Flexible and beautiful graphics:

6. Why do your plotting in R?
Flexible and beautiful graphics:

7. Enough slides! Now for a
live demo

8. *
Challenge 1:
Building a plot layer by
layer
1. Use the 'iris' dataset to build the following three
plots:
a. A plot of Sepal.Length vs. Sepal.Width
b. The same plot, but coloured by 'Species'
c. A plot of Petal.Length vs. Species

9. *
Challenge 2:
Playing with aesthetics
and geoms
1. Use the qplot function and the 'iris' dataset to re-
build the following three plots:
a. A plot of Sepal.Length vs. Sepal.Width
b. The same plot, but coloured by 'Species'
c. A plot of Petal.Length vs. Species
2. For the plot in part 'c', try changing the geom
argument to "boxplot". Try building a graph with
both points and boxplot on them

10. *
Challenge 3:
Faceting and scaling
1. Try to build the following plots using the iris data:
a. Petal.Width vs. Petal.Height, faceted in a row
by Species; and the same plot by column
b. Sepal.Width vs. Sepal.Height, with the x-axis
log-transformed, the y-axis log-transformed,
and both axes log-transformed

11. ggplot2: using the Grammar of
Graphics
ggplot2: a different way of plotting: building
plots by describing what you want, and let it
figure out how to plot it.

12. ggplot2: using the Grammar of
Graphics
ggplot2:
Builds plots out of simpler components:
● data
● aesthetics: e.g. coordinates, colour, size of points
● geoms: the type of plot layer: line, point, etc.
● facets: organizing graphs into subplots
● transforms: logs, square roots, continuous to discrete
etc.
● stats: functions of the raw data
● coordinates: e.g. Euclidean, map coords, polar
● themes: font size, grids, etc.