The Coordinates Layer IN TERMEDIATE DATA VIS UALIZ ATION W ITH - - PowerPoint PPT Presentation

the coordinates layer
SMART_READER_LITE
LIVE PREVIEW

The Coordinates Layer IN TERMEDIATE DATA VIS UALIZ ATION W ITH - - PowerPoint PPT Presentation

The Coordinates Layer IN TERMEDIATE DATA VIS UALIZ ATION W ITH GGP LOT2 Rick Scavetta Founder, Scavetta Academy Coordinates layer Controls plot dimensions coord_ e.g. coord_cartesian() INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2 Zooming


slide-1
SLIDE 1

The Coordinates Layer

IN TERMEDIATE DATA VIS UALIZ ATION W ITH GGP LOT2

Rick Scavetta

Founder, Scavetta Academy

slide-2
SLIDE 2

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Coordinates layer

Controls plot dimensions

coord_

e.g. coord_cartesian()

slide-3
SLIDE 3

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Zooming in

coord_cartesian(xlim = ...) scale_x_continuous(limits = ...) xlim(...)

slide-4
SLIDE 4

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Original plot

iris.smooth <- ggplot( iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species) ) + geom_point(alpha = 0.7) + geom_smooth() iris.smooth

slide-5
SLIDE 5

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

scale_x_continuous()

iris.smooth + scale_x_continuous(limits = c( Removed 95 rows containing non-f (stat_smooth). Removed 95 rows containing missi (geom_point).

slide-6
SLIDE 6

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

scale_x_continuous()

Original plot Zoom in with

scale_x_continuous()

Part of original data is ltered

  • ut!
slide-7
SLIDE 7

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

xlim()

iris.smooth + xlim(c(4.5, 5.5)) Removed 95 rows containing non-f (stat_smooth). Removed 95 rows containing missi (geom_point).

slide-8
SLIDE 8

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

coord_cartesian()

iris.smooth + coord_cartesian(xlim = c(4

slide-9
SLIDE 9

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Aspect ratio

Height-to-width ratio Watch out for deception! No universal standard so far Typically use 1:1 if data is on the same scale

slide-10
SLIDE 10

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Sunspots

library(zoo) sunspots.m <- data.frame( year = index(sunspot.month), value = reshape2::melt(sunsp ) ggplot(sunspots.m, aes(x = year, geom_line() + coord_fixed() # default to 1:1

slide-11
SLIDE 11

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Sunspots

ggplot(sunspots.m, aes(x = year, y = value)) + geom_line() + coord_fixed(0.055)

slide-12
SLIDE 12

Practice time!

IN TERMEDIATE DATA VIS UALIZ ATION W ITH GGP LOT2

slide-13
SLIDE 13

Coordinates vs. scales

IN TERMEDIATE DATA VIS UALIZ ATION W ITH GGP LOT2

Rick Scavetta

Founder, Scavetta Academy

slide-14
SLIDE 14

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Plot the raw data

ggplot(msleep, aes(bodywt, y = 1)) + geom_jitter() + scale_x_continuous(limits = c(0, 7000), breaks = seq(0, 7000, 1000))

slide-15
SLIDE 15

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Transform the raw data

ggplot(msleep, aes(log10(bodywt), y = 1)) + geom_jitter() + scale_x_continuous(limits = c(-3, 4), breaks = -3:4)

slide-16
SLIDE 16

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Add logtick annotation

ggplot(msleep, aes(log10(bodywt), y = 1)) + geom_jitter() + scale_x_continuous(limits = c(-3, 4), breaks = -3:4) + annotation_logticks(sides = "b")

slide-17
SLIDE 17

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Use scale_*_log10()

ggplot(msleep, aes(bodywt, y = 1)) + geom_jitter() + scale_x_log10(limits = c(1e-03, 1e+04))

slide-18
SLIDE 18

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Compare direct transform and scale_*_log10()

  • utput
slide-19
SLIDE 19

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Use coord_trans()

ggplot(msleep, aes(bodywt, y = 1)) + geom_jitter() + coord_trans(x = "log10")

slide-20
SLIDE 20

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Compare scale_*_log10() and coord_trans() output

slide-21
SLIDE 21

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Adjusting labels

slide-22
SLIDE 22

Time for exercises

IN TERMEDIATE DATA VIS UALIZ ATION W ITH GGP LOT2

slide-23
SLIDE 23

Double and ipped axes

IN TERMEDIATE DATA VIS UALIZ ATION W ITH GGP LOT2

Rick Scavetta

Founder, Scavetta Academy

slide-24
SLIDE 24

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Typical axis modications

Aspect ratios (see video 1) Adjust for best perspective Transformation functions (e.g. log, see video 2) Adjust if original scale is inappropriate Double x or y axes Add raw and transformed values Flipped axes Change direction of dependencies Change geometry orientation

slide-25
SLIDE 25

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Typical axis modications

Aspect ratios (see video 1) Adjust for best perspective Transformation functions (e.g. log, see video 2) Adjust if original scale is inappropriate Double x or y axes Add raw and transformed values Flipped axes Change direction of dependencies Change geometry orientation

See chapter 4, video 3 for more discussion on double x and y axes.

1 2

slide-26
SLIDE 26

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Double axes

slide-27
SLIDE 27

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Adding raw and transformed axes

slide-28
SLIDE 28

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Typical axis modications

Aspect ratios (see video 1) Adjust for best perspective Transformation functions (e.g. log, see video 2) Adjust if original scale is inappropriate Double x or y axes Add raw and transformed values Flipped axes Change direction of dependencies Change geometry orientation

slide-29
SLIDE 29

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Flipping axes

ggplot(iris, aes(x = Sepal.L y = Sepal.W color = Spe geom_point() + geom_smooth(method = "lm", se = FALSE)

slide-30
SLIDE 30

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

coord_ip()

ggplot(iris, aes(x = Sepal.L y = Sepal.W color = Spe geom_point() + geom_smooth(method = "lm", se = FALSE) + coord_flip()

slide-31
SLIDE 31

Let's practice!

IN TERMEDIATE DATA VIS UALIZ ATION W ITH GGP LOT2

slide-32
SLIDE 32

Polar coordinates

IN TERMEDIATE DATA VIS UALIZ ATION W ITH GGP LOT2

Rick Scavetta

Founder, Scavetta Academy

slide-33
SLIDE 33

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Projections control perception

Cartesian (2d) Orthogonal x and y-axes Modify axis limits and aspect ratio

slide-34
SLIDE 34

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Projections control perception

Cartesian (2d) Orthogonal x and y-axes Modify axis limits and aspect ratio Maps Many possible projections See next course

slide-35
SLIDE 35

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

A preview of map projections

The Mercator Projection The Conic Projection

slide-36
SLIDE 36

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

Polar coordinates

Cartesian (2d) Orthogonal x and y-axes. Maps Many projections, see next course Polar Transformed Cartesian space

slide-37
SLIDE 37

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

coord_polar()

p + coord_fixed() p + coord_polar()

slide-38
SLIDE 38

INTERMEDIATE DATA VISUALIZATION WITH GGPLOT2

coord_polar(theta = "y")

p + coord_fixed() p + coord_polar(theta = "y")

slide-39
SLIDE 39

Let's practice!

IN TERMEDIATE DATA VIS UALIZ ATION W ITH GGP LOT2