Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
Grammar of Graphics:
Visualizing Data Leslie McIntosh
Machine Learning & Data Science Meetup February 2013 – St. Louis, MO
Overview • Problem • Grammar of Graphics – Leland Wilkenson
o Syntax o Semantics
• Ggplot – Hadley Wickham • Example - Leslie • Example - Divya • Q&A
Background & Perspective
How do you obtain data?
How do you get meaningful information
from data?
Where is visualization in the data process cycle?
What is a statistical graphic?
Leland Wilkinson: The Grammar of Graphics 2nd Edition
Premises • Pipeline does not mandate implementation of
system
• Cannot change the order of the pipeline
Syntax
Step 1: Extract data from source
to create variables
Variables
Step 2: Apply algebra to varset
Algebra
Step 3: Apply scales to varset
Scales
Step 4: Compute statistics
on varset
Statistics
Step 5: Construct geometry to
produce graph
Geometry
Step 6: Apply coordinates to graph
Coordinates
Step 7: Compute aesthetics to
create graphic
Aesthetics
Aesthetic AQributes Form Surface Motion Sound Text Position Size Shape • Polygon • Glyph • Image Rotation Resolution
Color • Hue • Brightness • Saturation Texture • PaQern • Granularity • Orientation Blur Transparency
Direction Speed Acceleration
Tone Volume Rhythm Voice
Label
Semantics
Space • Two spaces to make a graphic
o The underlying space o Display space
Time • Time is ordered • Time is continuous • Time zones are discrete • Time intervals are additive • Time is cyclical • Time is independent of location (perceived)
Uncertainty • Variability • Noise • Incompleteness • Indeterminacy • Bias • Error • Accuracy • Precision • Reliability • Validity • Quality • Integrity
Graphic: Hadley Wickham docs.ggplot2.org
Analysis
!
Graphic: Leslie McIntosh
Control & Automation • Divya’s example
Tools of Data Visualization
• R o ggplot2 - Hadley Wickham o Shiny
• SPSS o Leland Wilkinson et al
• SAS • D3 • GGobi
ggplot2 Properties • Data • Scales • Stats • Geoms • Coordinates • Faceting • Themes
Scaling • Controls the mapping between data and
aesthetics • Can be mapped to a variable or be constant • Examples
o Legend o Colour-gradient o Shape
Geoms • Determine the type of plot • Examples
o Area o Bars o Boxplot o Histogram o Raster o Ribbon
Aesthetics • Can be mapped to a variable or be constant
Examples
Grammar of Graphics and ggplot describe rules and give a tool,
but not how to decide to properly represent data
Perinatal/Infant Mortality Rates of Delayed-‐‑Delivered Second Twin
0%
20%
40%
60%
80%
Gestational Age (Weeks)
Delay 61% 37% 18% 7%
No Delay 74% 37% 9% 4%
18-23 24-26 27-29 30+
It is easy to deceive with poor visualizations, it is more difficult to portray the truth without them.
Incremental changes in aesthetics should reflect and be perceived as proportional and/or
meaningful changes in data
Example
Communication Network
Insurance Map
Final Comments