STAT 209 A Taxonomy of Graphics February 16, 2018 Colin Reimer - - PowerPoint PPT Presentation

stat 209 a taxonomy of graphics
SMART_READER_LITE
LIVE PREVIEW

STAT 209 A Taxonomy of Graphics February 16, 2018 Colin Reimer - - PowerPoint PPT Presentation

Review ggplot2 Big Picture Types of Graphs ( geom s) Color Schemes ggplot2 themes STAT 209 A Taxonomy of Graphics February 16, 2018 Colin Reimer Dawson 1 / 39 Review ggplot2 Big Picture Types of Graphs ( geom s) Color Schemes


slide-1
SLIDE 1

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

STAT 209 A Taxonomy of Graphics

February 16, 2018 Colin Reimer Dawson 1 / 39

slide-2
SLIDE 2

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Course Business

  • HW3 or GitHub issues?
  • Project 1 Description
  • New, exciting reference resources!
  • Everybody met with/signed up to meet w/ me?
  • Office hours schedule

2 / 39

slide-3
SLIDE 3

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Today

  • Plot (geom) types
  • Color palettes
  • ggplot2 themes

3 / 39

slide-4
SLIDE 4

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Next Week

  • Monday: Lab on colors and themes
  • Wednesday: Lab to “reverse engineer” a published

visualization

  • Friday: Project 1 workshop

4 / 39

slide-5
SLIDE 5

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Outline

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes 5 / 39

slide-6
SLIDE 6

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Quick Summary: ggplot2

Figure: Slide by Jordan Crouser at Smith College

6 / 39

slide-7
SLIDE 7

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Quick Summary: ggplot2

Figure: Slide by Jordan Crouser at Smith College

6 / 39

slide-8
SLIDE 8

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Quick Summary: ggplot2

Figure: Slide by Jordan Crouser at Smith College

6 / 39

slide-9
SLIDE 9

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Quick Summary: ggplot2

Figure: Slide by Jordan Crouser at Smith College

6 / 39

slide-10
SLIDE 10

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Quick Summary: ggplot2

Figure: Slide by Jordan Crouser at Smith College

6 / 39

slide-11
SLIDE 11

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Quick Summary: ggplot2

Figure: Slide by Jordan Crouser at Smith College

6 / 39

slide-12
SLIDE 12

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Outline

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes 7 / 39

slide-13
SLIDE 13

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Common Graph Types

  • Bar Graph
  • Histogram
  • Box Plot
  • Scatterplot
  • Line Chart
  • Map

8 / 39

slide-14
SLIDE 14

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Bar Graph

  • Allows comparison of a statistic (often just “amount of

data”) across categories

  • Can use grouping or stacking to bring in a second

categorical variable and depict combinations 9 / 39

slide-15
SLIDE 15

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Histogram

  • Show count or proportion within bins of a quantitative

variable

  • Choice of bin width/cutoffs can affect impression

dramatically 10 / 39

slide-16
SLIDE 16

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Box Plot

  • Alternative to histogram to show distribution of a

quantitative variable

  • Can group by a categorical variable to compare

distributions 11 / 39

slide-17
SLIDE 17

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Scatterplot

  • Depicts the relationship between two quantitative

variables

  • Can bring in additional variables using hue, saturation,

symbol

  • Can show trend line based on a model (e.g., regression)

12 / 39

slide-18
SLIDE 18

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Line Chart

  • Useful to depict trends in sequential data
  • Essentially a scatterplot with dots connected, but this

must make sense

  • Can depict groups, or overlay multiple variables to see

when variables move together/apart/switch ordering 13 / 39

slide-19
SLIDE 19

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Map

  • Useful for geographic data (duh)
  • A filled map (like this) is called a chloropleth
  • May alternatively plot data point in specific locations

14 / 39

slide-20
SLIDE 20

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Pitfalls and Distortions of Maps

15 / 39

slide-21
SLIDE 21

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Pitfalls and Distortions of Maps

15 / 39

slide-22
SLIDE 22

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Pitfalls and Distortions of Maps

15 / 39

slide-23
SLIDE 23

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Pitfalls and Distortions of Maps

15 / 39

slide-24
SLIDE 24

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Pitfalls and Distortions of Maps

15 / 39

slide-25
SLIDE 25

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

My Personal Fave

Figure: http://xkcd.com/1939/

16 / 39

slide-26
SLIDE 26

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Outline

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes 17 / 39

slide-27
SLIDE 27

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Choose Colors Intentionally

  • Color is not just about aesthetic preference! Colors

communicate information

  • Universal design: Keep in mind not everyone sees color

the same way 18 / 39

slide-28
SLIDE 28

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Color Coordinate Systems

  • RGB (Red/Green/Blue)
  • denotes intensity of each primary color in the color
  • useful for color generation, not particularly intuitive for

color perception

  • HSL (Hue/Saturation/Lightness)
  • More naturally describe perceptual properties
  • Hue: the dominant “color word” in the rainbow
  • Saturation: how “pure” vs. “muted” is the color
  • Lightness: how much white or black is in the color

19 / 39

slide-29
SLIDE 29

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Taxonomy of Color Palettes

  • Sequential: Colors fall on an ordered scale
  • Single hue: Uses only saturation/lightness to distinguish
  • Multi hue: Varies colors on a hue spectrum
  • Diverging: Colors move two directions from a neutral

point

  • Categorical: No sense of a quantitative scale; mapping for

categorical variables only 20 / 39

slide-30
SLIDE 30

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Sequential Palette: Single Hue

  • Maps a numeric variable

to the saturation dimension (sometimes combination of saturation and lightness)

  • Higher saturation =

More of the thing 21 / 39

slide-31
SLIDE 31

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Sequential Palette: Multi Hue

  • Maps a numeric variable

to an arc in HSB color space, varying hue

  • Typically, darker = more

22 / 39

slide-32
SLIDE 32

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Diverging Palette

  • Two sequential (single

hue) scales that “meet in the middle” at a neutral (low saturation) color

  • Useful for signed

quantitative variable with anchor at zero

  • Careful to distinguish

missing data! 23 / 39

slide-33
SLIDE 33

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Categorical Palette

  • A set of (roughly)

equally spaced points in a circle in HSB space (i.e., only hue varies)

  • Colors indicate levels of

a categorical variable 24 / 39

slide-34
SLIDE 34

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Some convenient built-in options

  • RColorBrewer
  • by Cynthia Brewer (http://www.colorbrewer2.org)
  • has sequential, diverging, categorical palettes
  • viridis
  • Rudis, Ross and Garnier (link to CRAN documentation)
  • Based on color schemes in Python’s matplotlib
  • Sequential (multi-hue) only

25 / 39

slide-35
SLIDE 35

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

ggplot2 default

library(tidyverse) rand_data <- data.frame(x = rnorm(10000), y = rnorm(10000)) norm_plot <- ggplot(rand_data, aes(x = x, y = y)) + geom_hex() + coord_fixed() norm_plot

−5.0 −2.5 0.0 2.5 −4 −2 2 4

x y

25 50 75 100

count

26 / 39

slide-36
SLIDE 36

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

ColorBrewer Purples palette

library(RColorBrewer) norm_plot + scale_fill_distiller(palette = "Purples")

−5.0 −2.5 0.0 2.5 −4 −2 2 4

x y

25 50 75 100

count

27 / 39

slide-37
SLIDE 37

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

ColorBrewer YlGn palette

library(RColorBrewer) norm_plot + scale_fill_distiller(palette = "YlGn")

−5.0 −2.5 0.0 2.5 −4 −2 2 4

x y

25 50 75 100

count

28 / 39

slide-38
SLIDE 38

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

viridis palette

library(viridis) norm_plot + scale_fill_viridis()

−5.0 −2.5 0.0 2.5 −4 −2 2 4

x y

25 50 75 100

count

29 / 39

slide-39
SLIDE 39

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Universal Design: Color Blindness

30 / 39

slide-40
SLIDE 40

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Universal Design: Color Blindness

30 / 39

slide-41
SLIDE 41

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Universal Design: Color Blindness

30 / 39

slide-42
SLIDE 42

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Universal Design: Color Blindness

30 / 39

slide-43
SLIDE 43

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Outline

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes 31 / 39

slide-44
SLIDE 44

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

ggplot2 themes

library(tidyverse) p1 <- ggplot(mtcars, aes(x = disp, y = mpg, color = factor(cyl))) + geom_point() p1

  • 10

15 20 25 30 35 100 200 300 400

disp mpg factor(cyl)

  • 4

6 8

32 / 39

slide-45
SLIDE 45

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Wall Street Journal Theme

library(ggthemes) p1 + theme_wsj()

  • 10

15 20 25 30 35 100 200 300 400

factor(cyl)

  • 4

6 8

33 / 39

slide-46
SLIDE 46

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Economist Theme

library(ggthemes) p1 + theme_economist()

  • 10

15 20 25 30 35 100 200 300 400 disp mpg factor(cyl)

  • 4

6 8

34 / 39

slide-47
SLIDE 47

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

FiveThirtyEight Theme

library(ggthemes) p1 + theme_fivethirtyeight()

  • 10

15 20 25 30 35 100 200 300 400

factor(cyl)

  • 4

6 8

35 / 39

slide-48
SLIDE 48

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Solarized Theme

library(ggthemes) p1 + theme_solarized()

  • 10

15 20 25 30 35 100 200 300 400

disp mpg factor(cyl)

  • 4

6 8

36 / 39

slide-49
SLIDE 49

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Edward Tufte’s Minimalist Theme

library(ggthemes) p1 + theme_tufte()

  • 10

15 20 25 30 35 100 200 300 400

disp mpg factor(cyl)

  • 4

6 8

37 / 39

slide-50
SLIDE 50

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Why Does This Exist?

library(ggthemes) p1 + theme_excel()

  • 10

15 20 25 30 35 100 200 300 400

disp mpg factor(cyl)

  • 4

6 8

38 / 39

slide-51
SLIDE 51

Review ‘ggplot2‘ Big Picture Types of Graphs (geoms) Color Schemes ggplot2 themes

Many More...

  • ggthemes package documentation link

39 / 39