Mosaic plot in R.
-
Upload
volkan-oban -
Category
Data & Analytics
-
view
73 -
download
7
Transcript of Mosaic plot in R.
![Page 1: Mosaic plot in R.](https://reader035.fdocuments.in/reader035/viewer/2022081823/587362c11a28abe7648b5ff3/html5/thumbnails/1.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022081823/587362c11a28abe7648b5ff3/html5/thumbnails/2.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022081823/587362c11a28abe7648b5ff3/html5/thumbnails/3.jpg)
Example:
> library(vcd)> mosaic(HairEyeColor, shade=TRUE, legend=TRUE)
![Page 4: Mosaic plot in R.](https://reader035.fdocuments.in/reader035/viewer/2022081823/587362c11a28abe7648b5ff3/html5/thumbnails/4.jpg)
Example:
>library(vcd)> require(stats)> mosaicplot(Titanic, main = "Survival on the Titanic", color = TRUE)
![Page 5: Mosaic plot in R.](https://reader035.fdocuments.in/reader035/viewer/2022081823/587362c11a28abe7648b5ff3/html5/thumbnails/5.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022081823/587362c11a28abe7648b5ff3/html5/thumbnails/6.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022081823/587362c11a28abe7648b5ff3/html5/thumbnails/7.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022081823/587362c11a28abe7648b5ff3/html5/thumbnails/8.jpg)
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