Combining scales DATA VISU AL IZATION W ITH L ATTIC E IN R Deepa - - PowerPoint PPT Presentation

combining scales
SMART_READER_LITE
LIVE PREVIEW

Combining scales DATA VISU AL IZATION W ITH L ATTIC E IN R Deepa - - PowerPoint PPT Presentation

Combining scales DATA VISU AL IZATION W ITH L ATTIC E IN R Deepa y an Sarkar Associate Professor , Indian Statistical Instit u te Chapter goals Control and annotation of a x is limits Control v is u al appearance ( graphical parameters ) DATA


slide-1
SLIDE 1

Combining scales

DATA VISU AL IZATION W ITH L ATTIC E IN R

Deepayan Sarkar

Associate Professor, Indian Statistical Institute

slide-2
SLIDE 2

DATA VISUALIZATION WITH LATTICE IN R

Chapter goals

Control and annotation of axis limits Control visual appearance (graphical parameters)

slide-3
SLIDE 3

DATA VISUALIZATION WITH LATTICE IN R

The USMortality dataset

library(lattice); str(USMortality) 'data.frame': 40 obs. of 5 variables: $ Status: Factor w/ 2 levels "Rural","Urban": 2 1 2 1 2 1 2 1 2 1 $ Sex : Factor w/ 2 levels "Female","Male": 2 2 1 1 2 2 1 1 2 2 $ Cause : Factor w/ 10 levels "Alzheimers","Cancer",..: 6 6 6 6 2 $ Rate : num 210 243 132 155 196 ... $ SE : num 0.2 0.6 0.2 0.4 0.2 0.5 0.2 0.4 0.1 0.3 ...

slide-4
SLIDE 4

DATA VISUALIZATION WITH LATTICE IN R

The USMortality dataset

levels(USMortality$Cause) [1] "Alzheimers" "Cancer" [3] "Cerebrovascular diseases" "Diabetes" [5] "Flu and pneumonia" "Heart disease" [7] "Lower respiratory" "Nephritis" [9] "Suicide" "Unintentional injuries" USMortality <- dplyr::mutate(USMortality, Cause = reorder(Cause, Rat

slide-5
SLIDE 5

DATA VISUALIZATION WITH LATTICE IN R

Leading causes of death: dot plots

dotplot(Cause ~ Rate | Sex + Status, USMortality, as.table = TRUE)

slide-6
SLIDE 6

DATA VISUALIZATION WITH LATTICE IN R

Default axis limits

Common to all panels Chosen to cover the data range This is useful because common limits make panels easier to compare we save space by not drawing axes for each panel

slide-7
SLIDE 7

DATA VISUALIZATION WITH LATTICE IN R

Leading causes of death, again

dotplot(Cause ~ Rate | Sex + Status, USMortality, as.table = TRUE)

slide-8
SLIDE 8

DATA VISUALIZATION WITH LATTICE IN R

Controlling axis computation

Controlled using the scales argument. List with named sub-components Most common sub-component: relation

relation = "same" : common limits (default) relation = "free" : independent limits relation = "sliced" : dierent with same range

slide-9
SLIDE 9

DATA VISUALIZATION WITH LATTICE IN R

Controlling axis computation

dotplot(Cause ~ Rate | Sex + Status, USMortality, as.table = TRUE, scales = list(x = list(relation = "free")))

slide-10
SLIDE 10

Let's practice!

DATA VISU AL IZATION W ITH L ATTIC E IN R

slide-11
SLIDE 11

Logarithmic scales

DATA VISU AL IZATION W ITH L ATTIC E IN R

Deepayan Sarkar

Associate Professor, Indian Statistical Institute

slide-12
SLIDE 12

DATA VISUALIZATION WITH LATTICE IN R

Grouping by status

dotplot(Cause ~ Rate | Sex, data = USMortality, groups = Status, auto.key = TRUE)

slide-13
SLIDE 13

DATA VISUALIZATION WITH LATTICE IN R

Logarithmic scales

dotplot(Cause ~ log(Rate) | Sex, data = USMortality, groups = Status, auto.key = list(columns = 2))

slide-14
SLIDE 14

DATA VISUALIZATION WITH LATTICE IN R

Logarithmic scales

dotplot(Cause ~ Rate | Sex, USMortality, groups = Status, scales = list(x = list(log = 2)), auto.key = list(columns = 2))

slide-15
SLIDE 15

DATA VISUALIZATION WITH LATTICE IN R

Logarithmic scales

dotplot(Cause ~ Rate | Sex, USMortality, groups = Status, scales = list(x = list(log = 2, equispaced.log = FALSE)), auto.key = list(columns = 2))

slide-16
SLIDE 16

Let's practice!

DATA VISU AL IZATION W ITH L ATTIC E IN R

slide-17
SLIDE 17

Graphical parameters

DATA VISU AL IZATION W ITH L ATTIC E IN R

Deepayan Sarkar

Associate Professor, Indian Statistical Institute

slide-18
SLIDE 18

DATA VISUALIZATION WITH LATTICE IN R

Graphical parameters

Two standard approaches in base graphics:

par() function to make persistent changes

  • ptional arguments in function calls

Analogous approaches available in laice.

slide-19
SLIDE 19

DATA VISUALIZATION WITH LATTICE IN R

Using a global theme

library(latticeExtra) new.theme <- ggplot2like()

  • ld.theme <- trellis.par.get()

trellis.par.set(new.theme) dotplot(Cause ~ Rate | Sex, data = USMortality, groups = Status, auto.key = list(columns = 2), between = list(x = 0.5), scales = list(x = list(log = 2, equispaced.log = FALSE))) trellis.par.set(old.theme)

slide-20
SLIDE 20

DATA VISUALIZATION WITH LATTICE IN R

Using a global theme

slide-21
SLIDE 21

DATA VISUALIZATION WITH LATTICE IN R

Making minor changes

dotplot(Cause ~ Rate | Sex, USMortality, groups = Status, pch = 15, col = c("red", "blue"), scales = list(x = list(log = 2, equispaced.log = FALSE)))

slide-22
SLIDE 22

Let's practice!

DATA VISU AL IZATION W ITH L ATTIC E IN R

slide-23
SLIDE 23

Using simpleTheme()

DATA VISU AL IZATION W ITH L ATTIC E IN R

Deepayan Sarkar

Associate Professor, Indian Statistical Institute

slide-24
SLIDE 24

DATA VISUALIZATION WITH LATTICE IN R

Plotting symbols

dotplot(Cause ~ Rate | Sex, USMortality, groups = Status, auto.key = list(columns = 2), scales = list(x = list(log = 2, equispaced.log = FALSE)))

slide-25
SLIDE 25

DATA VISUALIZATION WITH LATTICE IN R

Changing symbol and color

dotplot(Cause ~ Rate | Sex, USMortality, groups = Status, auto.key = list(columns = 2), pch = 16, col = c("red","blue"), scales = list(x = list(log = 2, equispaced.log = FALSE)))

slide-26
SLIDE 26

DATA VISUALIZATION WITH LATTICE IN R

Using simpleTheme()

dotplot(Cause ~ Rate | Sex, USMortality, groups = Status, auto.key = list(columns = 2), par.settings = simpleTheme(pch = 16, col = c("red","blue")), scales = list(x = list(log = 2, equispaced.log = FALSE)))

slide-27
SLIDE 27

Let's practice!

DATA VISU AL IZATION W ITH L ATTIC E IN R