Visible aesthetics IN TR OD U C TION TO DATA VISU AL IZATION W ITH - - PowerPoint PPT Presentation

visible aesthetics
SMART_READER_LITE
LIVE PREVIEW

Visible aesthetics IN TR OD U C TION TO DATA VISU AL IZATION W ITH - - PowerPoint PPT Presentation

Visible aesthetics IN TR OD U C TION TO DATA VISU AL IZATION W ITH G G P L OT 2 Rick Sca v e a Fo u nder , Sca v e a Academ y Mapping onto the X and Y a x es ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point()


slide-1
SLIDE 1

Visible aesthetics

IN TR OD U C TION TO DATA VISU AL IZATION W ITH G G P L OT2

Rick Scavea

Founder, Scavea Academy

slide-2
SLIDE 2

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Mapping onto the X and Y axes

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point()

slide-3
SLIDE 3

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Mapping onto color

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point()

Type Variable Color Species

slide-4
SLIDE 4

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Mapping onto the color aesthetic

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point()

Type Variable Color Species Species, a dataframe column, is mapped onto color, a visible aesthetic.

slide-5
SLIDE 5

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Mapping onto the color aesthetic

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point()

Type Variable Color Species Species, a dataframe column, is mapped onto color, a visible aesthetic. Map aesthetics in aes() .

slide-6
SLIDE 6

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Mapping onto the color aesthetic in geom

ggplot(iris) + geom_point(aes(x = Sepal.Length, y = Sepal.Width, col = Species))

Only necessary if: All layers should not inherit the same aesthetics Mixing dierent data sources

slide-7
SLIDE 7

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Typical visible aesthetics

Aesthetic Description x X axis position y Y axis position

slide-8
SLIDE 8

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Typical visible aesthetics

Aesthetic Description x X axis position y Y axis position ll Fill color

slide-9
SLIDE 9

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Typical visible aesthetics

Aesthetic Description x X axis position y Y axis position ll Fill color color Color of points, outlines of other geoms

slide-10
SLIDE 10

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Typical visible aesthetics

Aesthetic Description x X axis position y Y axis position ll Fill color color Color of points, outlines of other geoms size Area or radius of points, thickness of lines

slide-11
SLIDE 11

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Typical visible aesthetics

Aesthetic Description x X axis position y Y axis position ll Fill color color Color of points, outlines of other geoms size Area or radius of points, thickness of lines Aesthetic Description alpha Transparency

slide-12
SLIDE 12

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Typical visible aesthetics

Aesthetic Description x X axis position y Y axis position ll Fill color color Color of points, outlines of other geoms size Area or radius of points, thickness of lines Aesthetic Description alpha Transparency linetype Line dash paern

slide-13
SLIDE 13

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Typical visible aesthetics

Aesthetic Description x X axis position y Y axis position ll Fill color color Color of points, outlines of other geoms size Area or radius of points, thickness of lines Aesthetic Description alpha Transparency linetype Line dash paern labels Text on a plot or axes

slide-14
SLIDE 14

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Typical visible aesthetics

Aesthetic Description x X axis position y Y axis position ll Fill color color Color of points, outlines of other geoms size Area or radius of points, thickness of lines Aesthetic Description alpha Transparency linetype line dash paern labels Text on a plot or axes shape Shape

slide-15
SLIDE 15

Let's Practice

IN TR OD U C TION TO DATA VISU AL IZATION W ITH G G P L OT2

slide-16
SLIDE 16

Using attributes

IN TR OD U C TION TO DATA VISU AL IZATION W ITH G G P L OT2

Rick Scavea

Founder, Scavea Academy

slide-17
SLIDE 17

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Aesthetics? Attributes!

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point(color = "red")

Type Property Color "red" Set aributes in geom_*() . The color aribute is set to "red".

slide-18
SLIDE 18

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Aesthetics? Attributes!

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point(size = 10)

Type Property Size 4

slide-19
SLIDE 19

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Aesthetics? Attributes!

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point(shape = 4)

Type Property Shape 4

slide-20
SLIDE 20

Let's practice!

IN TR OD U C TION TO DATA VISU AL IZATION W ITH G G P L OT2

slide-21
SLIDE 21

Modifying Aesthetics

IN TR OD U C TION TO DATA VISU AL IZATION W ITH G G P L OT2

Rick Scavea

Founder, Scavea Academy

slide-22
SLIDE 22

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Positions

Adjustment for overlapping identity dodge stack ll jier jierdodge nudge

slide-23
SLIDE 23

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

position = "identity" (default)

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point()

slide-24
SLIDE 24

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

position = "identity" (default)

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = "identity")

slide-25
SLIDE 25

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

position = "jitter"

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = "jitter")

slide-26
SLIDE 26

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

position_jitter()

posn_j <- position_jitter(0.1) ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, col = Species)) + geom_point(position = posn_j)

slide-27
SLIDE 27

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

position_jitter()

posn_j <- position_jitter(0.1, seed = 136) ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = posn_j)

Set arguments for the position Consistency across plots & layers

slide-28
SLIDE 28

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Scale functions

scale_x_*() scale_y_*() scale_color_*()

Also scale_colour_*()

scale_fill_*() scale_shape_*() scale_linetype_*() scale_size_*()

slide-29
SLIDE 29

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Scale functions

scale_x_continuous() scale_y_*() scale_color_discrete()

Alternatively, scale_colour_*()

scale_fill_*() scale_shape_*() scale_linetype_*() scale_size_*()

slide-30
SLIDE 30

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

scale_*_*()

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = "jitter") + scale_x_continuous("Sepal Length") + scale_color_discrete("Species")

slide-31
SLIDE 31

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

The limits argument

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = "jitter") + scale_x_continuous("Sepal Length", limits = c(2,8)) + scale_color_discrete("Species")

slide-32
SLIDE 32

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

The breaks argument

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = "jitter") + scale_x_continuous("Sepal Length", limits = c(2, 8), breaks = seq(2, 8, 3)) + scale_color_discrete("Species")

slide-33
SLIDE 33

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

The expand argument

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = "jitter") + scale_x_continuous("Sepal Length", limits = c(2, 8), breaks = seq(2, 8, 3), expand = c(0, 0)) + scale_color_discrete("Species")

slide-34
SLIDE 34

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

The labels argument

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = "jitter") + scale_x_continuous("Sepal Length", limits = c(2, 8), breaks = seq(2, 8, 3), expand = c(0, 0), labels = c("Setosa", "Versicolor", "Virginica")) + scale_color_discrete("Species")

slide-35
SLIDE 35

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

labs()

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = "jitter") + labs(x = "Sepal Length", y = "Sepal Width", color = "Species")

slide-36
SLIDE 36

Let's try it out!

IN TR OD U C TION TO DATA VISU AL IZATION W ITH G G P L OT2

slide-37
SLIDE 37

Aesthetics best practices

IN TR OD U C TION TO DATA VISU AL IZATION W ITH G G P L OT2

Rick Scavea

Founder, Scavea Academy

slide-38
SLIDE 38

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Which aesthetics?

Use your creative know-how, and Follow some clear guidelines Jacques Bertin The Semiology of Graphics, 1967 William Cleveland The Elements of Graphing Data, 1985 Visualizing Data, 1993

slide-39
SLIDE 39

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Form follows function

slide-40
SLIDE 40

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Form follows function

Function Primary: Accurate and ecient representations Secondary: Visually appealing, beautiful plots Guiding principles Never: Misrepresent or obscure data Confuse viewers with complexity Always: Consider the audience and purpose of every plot

slide-41
SLIDE 41

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

slide-42
SLIDE 42

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

slide-43
SLIDE 43

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Extracting information from Data

slide-44
SLIDE 44

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

slide-45
SLIDE 45

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

slide-46
SLIDE 46

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

slide-47
SLIDE 47

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

The best choices for aesthetics

Ecient Provides a faster overview than numeric summaries Accurate Minimizes information loss

slide-48
SLIDE 48

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Aesthetics - continuous variables

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point()

slide-49
SLIDE 49

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Aesthetics - continuous variables

ggplot(iris, aes(color = Sepal.Length, y = Sepal.Width, x = Species)) + geom_point()

slide-50
SLIDE 50

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

slide-51
SLIDE 51

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Three iris scatter plots

slide-52
SLIDE 52

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Three iris scatter plots, unaligned y-axes

slide-53
SLIDE 53

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Single faceted plot, common y-axis

slide-54
SLIDE 54

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

slide-55
SLIDE 55

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Aesthetics - categorical variables

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, col = Species)) + geom_point()

slide-56
SLIDE 56

INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT2

Aesthetics - categorical variables

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, col = Species)) + geom_point(position = "jitter", alpha = 0.5)

slide-57
SLIDE 57

Now it's your turn

IN TR OD U C TION TO DATA VISU AL IZATION W ITH G G P L OT2