Welcome to the co u rse DATA VISU AL IZATION W ITH L ATTIC E IN - - PowerPoint PPT Presentation

welcome to the co u rse
SMART_READER_LITE
LIVE PREVIEW

Welcome to the co u rse DATA VISU AL IZATION W ITH L ATTIC E IN - - PowerPoint PPT Presentation

Welcome to the co u rse DATA VISU AL IZATION W ITH L ATTIC E IN R Deepa y an Sarkar Associate Professor , Indian Statistical Instit u te Data v is u ali z ation E x plorator y data anal y sis Presenting or reporting res u lts DATA


slide-1
SLIDE 1

Welcome to the course

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

Data visualization

Exploratory data analysis Presenting or reporting results

slide-3
SLIDE 3

DATA VISUALIZATION WITH LATTICE IN R

Data visualization frameworks in R

Base R graphics

lattice based on "Trellis graphics" (Cleveland) ggplot2 based on "Grammar of Graphics" (Wilkinson)

Number of packages depending on these (March 2017): graphics laice ggplot2 CRAN 5612 3654 1566 CRAN+BioC 7889 4858 2038

slide-4
SLIDE 4

DATA VISUALIZATION WITH LATTICE IN R

The USCancerRates dataset

Age-adjusted death rates due to cancer (per 100,000) Separately for males and females County-level data for 1999-2003 Available in the latticeExtra package

slide-5
SLIDE 5

DATA VISUALIZATION WITH LATTICE IN R

The USCancerRates dataset

data(USCancerRates, package = "latticeExtra") str(USCancerRates) 'data.frame': 3041 obs. of 8 variables: $ rate.male : num 364 346 341 336 330 ... $ LCL95.male : num 311 274 304 289 293 ... $ UCL95.male : num 423 431 381 389 371 ... $ rate.female : num 151 140 182 185 172 ... $ LCL95.female: num 124 103 161 157 151 ... $ UCL95.female: num 184 190 206 218 195 ... $ state : Factor w/ 49 levels "Alabama","Alaska",..: 1 1... $ county : chr [1:3041] "Pickens County" "Bullock County" ...

slide-6
SLIDE 6

DATA VISUALIZATION WITH LATTICE IN R

A histogram

library(lattice) histogram(~ rate.male, data = USCancerRates)

slide-7
SLIDE 7

DATA VISUALIZATION WITH LATTICE IN R

A scatter plot

xyplot(rate.female ~ rate.male, data = USCancerRates)

slide-8
SLIDE 8

DATA VISUALIZATION WITH LATTICE IN R

The formula

histogram(~ rate.male, data = USCancerRates) xyplot(rate.female ~ rate.male, USCancerRates) ~ x in histogram() : x ploed on x-axis y ~ x in xyplot() : x ploed on x-axis y ploed on y-axis

Similar to modeling calls

lm(rate.female ~ rate.male, data = USCancerRates)

slide-9
SLIDE 9

DATA VISUALIZATION WITH LATTICE IN R

A version for presentation

slide-10
SLIDE 10

Let's practice!

DATA VISU AL IZATION W ITH L ATTIC E IN R

slide-11
SLIDE 11

Optional arguments

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

Arguments in lattice functions

Mandatory:

x : formula (rst argument, usually not named) data : dataset containing variables

Optional: Some apply to all functions Some are specic to particular functions

slide-13
SLIDE 13

DATA VISUALIZATION WITH LATTICE IN R

Common arguments: main, xlab, ylab

histogram(~ rate.male, data = USCancerRates, main = "County-wise deaths due to cancer (1999-2003)", xlab = "Rate among males (per 100,000)")

slide-14
SLIDE 14

DATA VISUALIZATION WITH LATTICE IN R

xyplot(rate.female ~ rate.male, data = USCancerRates, main = "County-wise deaths due to cancer (1999-2003)", xlab = "Rate among males (per 100,000)", ylab = "Rate among females (per 100,000)")

slide-15
SLIDE 15

DATA VISUALIZATION WITH LATTICE IN R

Arguments of histogram()

histogram(~ rate.male, USCancerRates, nint = 30)

slide-16
SLIDE 16

DATA VISUALIZATION WITH LATTICE IN R

Arguments of xyplot()

xyplot(rate.female ~ rate.male, USCancerRates, grid = TRUE, abline = c(0, 1))

slide-17
SLIDE 17

Let's practice!

DATA VISU AL IZATION W ITH L ATTIC E IN R

slide-18
SLIDE 18

Box and whisker plots and reordering levels

DATA VISU AL IZATION W ITH L ATTIC E IN R

Deepayan Sarkar

Associate Professor, Indian Statistical Institute

slide-19
SLIDE 19

DATA VISUALIZATION WITH LATTICE IN R

Box and whisker plots: bwplot()

bwplot(~ rate.male, data = USCancerRates)

slide-20
SLIDE 20

DATA VISUALIZATION WITH LATTICE IN R

Comparative box and whisker plots

bwplot(state ~ rate.male, data = USCancerRates)

slide-21
SLIDE 21

DATA VISUALIZATION WITH LATTICE IN R

Reordering factor levels

USCancerRates <- dplyr::mutate(USCancerRates, state.ordered = reorder(state, rate.male, median, na.rm = TRUE)) bwplot(state.ordered ~ rate.male, USCancerRates)

slide-22
SLIDE 22

Let's practice!

DATA VISU AL IZATION W ITH L ATTIC E IN R