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 VISUALIZATION WITH LATTICE IN R
The USMortalit y 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 ... DATA VISUALIZATION WITH LATTICE IN R
The USMortalit y 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 DATA VISUALIZATION WITH LATTICE IN R
Leading ca u ses of death : dot plots dotplot(Cause ~ Rate | Sex + Status, USMortality, as.table = TRUE) DATA VISUALIZATION WITH LATTICE IN R
Defa u lt a x is limits Common to all panels Chosen to co v er the data range This is u sef u l beca u se common limits make panels easier to compare w e sa v e space b y not dra w ing a x es for each panel DATA VISUALIZATION WITH LATTICE IN R
Leading ca u ses of death , again dotplot(Cause ~ Rate | Sex + Status, USMortality, as.table = TRUE) DATA VISUALIZATION WITH LATTICE IN R
Controlling a x is comp u tation Controlled u sing the scales arg u ment . List w ith named s u b - components Most common s u b - component : relation relation = "same" : common limits ( defa u lt ) relation = "free" : independent limits relation = "sliced" : di � erent w ith same range DATA VISUALIZATION WITH LATTICE IN R
Controlling a x is comp u tation dotplot(Cause ~ Rate | Sex + Status, USMortality, as.table = TRUE, scales = list(x = list(relation = "free"))) DATA VISUALIZATION WITH LATTICE IN R
Let ' s practice ! DATA VISU AL IZATION W ITH L ATTIC E IN R
Logarithmic scales DATA VISU AL IZATION W ITH L ATTIC E IN R Deepa y an Sarkar Associate Professor , Indian Statistical Instit u te
Gro u ping b y stat u s dotplot(Cause ~ Rate | Sex, data = USMortality, groups = Status, auto.key = TRUE) DATA VISUALIZATION WITH LATTICE IN R
Logarithmic scales dotplot(Cause ~ log(Rate) | Sex, data = USMortality, groups = Status, auto.key = list(columns = 2)) 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)) 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)) DATA VISUALIZATION WITH LATTICE IN R
Let ' s practice ! DATA VISU AL IZATION W ITH L ATTIC E IN R
Graphical parameters DATA VISU AL IZATION W ITH L ATTIC E IN R Deepa y an Sarkar Associate Professor , Indian Statistical Instit u te
Graphical parameters T w o standard approaches in base graphics : par() f u nction to make persistent changes optional arg u ments in f u nction calls Analogo u s approaches a v ailable in la � ice . DATA VISUALIZATION WITH LATTICE IN R
Using a global theme library(latticeExtra) new.theme <- ggplot2like() old.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) DATA VISUALIZATION WITH LATTICE IN R
Using a global theme 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))) DATA VISUALIZATION WITH LATTICE IN R
Let ' s practice ! DATA VISU AL IZATION W ITH L ATTIC E IN R
Using simpleTheme () DATA VISU AL IZATION W ITH L ATTIC E IN R Deepa y an Sarkar Associate Professor , Indian Statistical Instit u te
Plotting s y mbols dotplot(Cause ~ Rate | Sex, USMortality, groups = Status, auto.key = list(columns = 2), scales = list(x = list(log = 2, equispaced.log = FALSE))) DATA VISUALIZATION WITH LATTICE IN R
Changing s y mbol 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))) 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))) DATA VISUALIZATION WITH LATTICE IN R
Let ' s practice ! DATA VISU AL IZATION W ITH L ATTIC E IN R
Recommend
More recommend