--- title: "Mosaic Plot" author: "Dirk Surmann" date: "`r Sys.Date()`" output: prettydoc::html_pretty: toc: true theme: cayman highlight: github vignette: > %\VignetteIndexEntry{Mosaic Plot} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r setup, include = FALSE} # show grouped code output instead of single lines # use '#>' for R outputs knitr::opts_chunk$set(collapse = TRUE, comment = "#>") ``` # Initial Situation and Goal One way to get a view on the structure in categorical data is the mosaic plot. An example of this type of data is the dataset 'Titanic' which is available in the demo data within 'Cornerstone'. A possible result is the following graph. ```{r mosaicPlotTitanic, echo=FALSE, fig.cap="Mosaic Plot of 'Titanic' data"} knitr::include_graphics("imgs/mosaicPlot01.png") ``` How do we realize this result in 'Cornerstone' using 'Mosaic Plot' from 'CornerstoneR'? # Cornerstone Workflow To achieve this result in 'Cornerstone' open a dataset, e.g. 'Titanic' and choose menu 'Analysis' -> 'CornerstoneR' -> 'Mosaic Plot' as shown in the following screenshot. ```{r mosaicPlotMenu, echo=FALSE, fig.cap="Mosaic Plot: Menu"} knitr::include_graphics("imgs/mosaicPlot02.png") ``` In the appearing dialog select variable 'pclass' and 'age' to predictors. 'sex' and 'survived' are the response variables. ```{r mosaicPlotVariables, echo=FALSE, fig.cap="Mosaic Plot: Variable Selection"} knitr::include_graphics("imgs/mosaicPlot03.png") ``` 'OK' confirms your selection and the following window appears. ```{r mosaicPlotRScript, echo=FALSE, fig.cap="Mosaic Plot: R Script"} knitr::include_graphics("imgs/mosaicPlot04.png") ``` Now, click the execute button (green arrow) or choose the menu 'R Script' -> 'Execute' and all calculations are done via 'R'. Calculations are done if the text at the lower left status bar contains 'Last execute error state: OK'. Our result is available via the menu 'Graphs' -> 'Mosaic Plot (PNG)' or 'Mosaic Plot (EMF)' as shown in the following screenshot. ```{r mosaicPlotResultMenu, echo=FALSE, fig.cap="Mosaic Plot: Result Menu"} knitr::include_graphics("imgs/mosaicPlot05.png") ``` After clicking this menu a 'Cornerstone' graph with the mosaic plot from R opens. ```{r mosaicPlotResultGraph, echo=FALSE, fig.cap="Mosaic Plot: Result Graph"} knitr::include_graphics("imgs/mosaicPlot01.png") ```