mosaic plot in r

8
Prepared by Volkan OBAN Visualizing Categorical Data Mosaic Plots: Example:

Upload: volkan-oban

Post on 09-Jan-2017

73 views

Category:

Data & Analytics


7 download

TRANSCRIPT

Page 1: Mosaic plot in R

Prepared by Volkan OBAN

Visualizing Categorical Data

Mosaic Plots:

Example:

mat <- matrix(c(120,230,84,70,130,83,13,26,18),3) dimnames(mat) <- list(c("good","fair","poor"),c("a","b","c")) mat

Page 2: Mosaic plot in R

a b cgood 120 70 13fair 230 130 26poor 84 83 18

library(vcd)mosaic(mat, shade=TRUE)

Example:

> library(vcd)> assoc(HairEyeColor, shade=TRUE)

Page 3: Mosaic plot in R

Example:

> library(vcd)> mosaic(HairEyeColor, shade=TRUE, legend=TRUE)

Page 4: Mosaic plot in R

Example:

>library(vcd)> require(stats)> mosaicplot(Titanic, main = "Survival on the Titanic", color = TRUE)

Page 5: Mosaic plot in R

Example:

> fm <- loglin(HairEyeColor, list(1, 2, 3))2 iterations: deviation 5.684342e-14 > pchisq(fm$pearson, fm$df, lower.tail = FALSE)[1] 5.320872e-23> mosaicplot(HairEyeColor, shade = TRUE, margin = list(1:2, 3))

Page 6: Mosaic plot in R

Example

> data(Titanic)> > mosaicplot(Titanic,main = "Survival on the Titanic",col = hcl(c(240, 120)),off = c(5, 5, 5, 5))

Page 7: Mosaic plot in R

Example:

> data(UCBAdmissions)> > mosaicplot(UCBAdmissions, sort = 3:1,col = hcl(c(120, 10)),main = "Student admissions at UC Berkeley")

Page 8: Mosaic plot in R

Ref: https://www.stat.auckland.ac.nz/~ihaka/120/Lectures/lecture17.pdfhttp://www.statmethods.net/advgraphs/mosaic.htmlhttps://stat.ethz.ch/R-manual/R-devel/library/graphics/html/mosaicplot.html