mosaic plot in r
TRANSCRIPT
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
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)
Example:
> library(vcd)> mosaic(HairEyeColor, shade=TRUE, legend=TRUE)
Example:
>library(vcd)> require(stats)> mosaicplot(Titanic, main = "Survival on the Titanic", color = TRUE)
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))
Example
> data(Titanic)> > mosaicplot(Titanic,main = "Survival on the Titanic",col = hcl(c(240, 120)),off = c(5, 5, 5, 5))
Example:
> data(UCBAdmissions)> > mosaicplot(UCBAdmissions, sort = 3:1,col = hcl(c(120, 10)),main = "Student admissions at UC Berkeley")
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