EVOLUTION-MANAGER
Edit File: mosaicplot.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Mosaic Plots</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for mosaicplot {graphics}"><tr><td>mosaicplot {graphics}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Mosaic Plots</h2> <h3>Description</h3> <p>Plots a mosaic on the current graphics device.</p> <h3>Usage</h3> <pre> mosaicplot(x, ...) ## Default S3 method: mosaicplot(x, main = deparse(substitute(x)), sub = NULL, xlab = NULL, ylab = NULL, sort = NULL, off = NULL, dir = NULL, color = NULL, shade = FALSE, margin = NULL, cex.axis = 0.66, las = par("las"), border = NULL, type = c("pearson", "deviance", "FT"), ...) ## S3 method for class 'formula' mosaicplot(formula, data = NULL, ..., main = deparse(substitute(data)), subset, na.action = stats::na.omit) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>a contingency table in array form, with optional category labels specified in the <code>dimnames(x)</code> attribute. The table is best created by the <code>table()</code> command.</p> </td></tr> <tr valign="top"><td><code>main</code></td> <td> <p>character string for the mosaic title.</p> </td></tr> <tr valign="top"><td><code>sub</code></td> <td> <p>character string for the mosaic sub-title (at bottom).</p> </td></tr> <tr valign="top"><td><code>xlab, ylab</code></td> <td> <p>x- and y-axis labels used for the plot; by default, the first and second element of <code>names(dimnames(X))</code> (i.e., the name of the first and second variable in <code>X</code>).</p> </td></tr> <tr valign="top"><td><code>sort</code></td> <td> <p>vector ordering of the variables, containing a permutation of the integers <code>1:length(dim(x))</code> (the default).</p> </td></tr> <tr valign="top"><td><code>off</code></td> <td> <p>vector of offsets to determine percentage spacing at each level of the mosaic (appropriate values are between 0 and 20, and the default is 20 times the number of splits for 2-dimensional tables, and 10 otherwise). Rescaled to maximally 50, and recycled if necessary.</p> </td></tr> <tr valign="top"><td><code>dir</code></td> <td> <p>vector of split directions (<code>"v"</code> for vertical and <code>"h"</code> for horizontal) for each level of the mosaic, one direction for each dimension of the contingency table. The default consists of alternating directions, beginning with a vertical split.</p> </td></tr> <tr valign="top"><td><code>color</code></td> <td> <p>logical or (recycling) vector of colors for color shading, used only when <code>shade</code> is <code>FALSE</code>, or <code>NULL</code> (default). By default, grey boxes are drawn. <code>color = TRUE</code> uses a gamma-corrected grey palette. <code>color = FALSE</code> gives empty boxes with no shading.</p> </td></tr> <tr valign="top"><td><code>shade</code></td> <td> <p>a logical indicating whether to produce extended mosaic plots, or a numeric vector of at most 5 distinct positive numbers giving the absolute values of the cut points for the residuals. By default, <code>shade</code> is <code>FALSE</code>, and simple mosaics are created. Using <code>shade = TRUE</code> cuts absolute values at 2 and 4.</p> </td></tr> <tr valign="top"><td><code>margin</code></td> <td> <p>a list of vectors with the marginal totals to be fit in the log-linear model. By default, an independence model is fitted. See <code><a href="../../stats/html/loglin.html">loglin</a></code> for further information.</p> </td></tr> <tr valign="top"><td><code>cex.axis</code></td> <td> <p>The magnification to be used for axis annotation, as a multiple of <code>par("cex")</code>.</p> </td></tr> <tr valign="top"><td><code>las</code></td> <td> <p>numeric; the style of axis labels, see <code><a href="par.html">par</a></code>.</p> </td></tr> <tr valign="top"><td><code>border</code></td> <td> <p>colour of borders of cells: see <code><a href="polygon.html">polygon</a></code>.</p> </td></tr> <tr valign="top"><td><code>type</code></td> <td> <p>a character string indicating the type of residual to be represented. Must be one of <code>"pearson"</code> (giving components of Pearson's <i>chi-squared</i>), <code>"deviance"</code> (giving components of the likelihood ratio <i>chi-squared</i>), or <code>"FT"</code> for the Freeman-Tukey residuals. The value of this argument can be abbreviated.</p> </td></tr> <tr valign="top"><td><code>formula</code></td> <td> <p>a formula, such as <code>y ~ x</code>.</p> </td></tr> <tr valign="top"><td><code>data</code></td> <td> <p>a data frame (or list), or a contingency table from which the variables in <code>formula</code> should be taken.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>further arguments to be passed to or from methods.</p> </td></tr> <tr valign="top"><td><code>subset</code></td> <td> <p>an optional vector specifying a subset of observations in the data frame to be used for plotting.</p> </td></tr> <tr valign="top"><td><code>na.action</code></td> <td> <p>a function which indicates what should happen when the data contains variables to be cross-tabulated, and these variables contain <code>NA</code>s. The default is to omit cases which have an <code>NA</code> in any variable. Since the tabulation will omit all cases containing missing values, this will only be useful if the <code>na.action</code> function replaces missing values.</p> </td></tr> </table> <h3>Details</h3> <p>This is a generic function. It currently has a default method (<code>mosaicplot.default</code>) and a formula interface (<code>mosaicplot.formula</code>). </p> <p>Extended mosaic displays visualize standardized residuals of a loglinear model for the table by color and outline of the mosaic's tiles. (Standardized residuals are often referred to a standard normal distribution.) Cells representing negative residuals are drawn in shaded of red and with broken borders; positive ones are drawn in blue with solid borders. </p> <p>For the formula method, if <code>data</code> is an object inheriting from class <code>"table"</code> or class <code>"ftable"</code> or an array with more than 2 dimensions, it is taken as a contingency table, and hence all entries should be non-negative. In this case the left-hand side of <code>formula</code> should be empty and the variables on the right-hand side should be taken from the names of the dimnames attribute of the contingency table. A marginal table of these variables is computed, and a mosaic plot of that table is produced. </p> <p>Otherwise, <code>data</code> should be a data frame or matrix, list or environment containing the variables to be cross-tabulated. In this case, after possibly selecting a subset of the data as specified by the <code>subset</code> argument, a contingency table is computed from the variables given in <code>formula</code>, and a mosaic is produced from this. </p> <p>See Emerson (1998) for more information and a case study with television viewer data from Nielsen Media Research. </p> <p>Missing values are not supported except via an <code>na.action</code> function when <code>data</code> contains variables to be cross-tabulated. </p> <p>A more flexible and extensible implementation of mosaic plots written in the grid graphics system is provided in the function <code><a href="../../vcd/html/mosaic.html">mosaic</a></code> in the contributed package <a href="https://CRAN.R-project.org/package=vcd"><span class="pkg">vcd</span></a> (Meyer, Zeileis and Hornik, 2006). </p> <h3>Author(s)</h3> <p>S-PLUS original by John Emerson <a href="mailto:john.emerson@yale.edu">john.emerson@yale.edu</a>. Originally modified and enhanced for <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> by Kurt Hornik. </p> <h3>References</h3> <p>Hartigan, J.A., and Kleiner, B. (1984). A mosaic of television ratings. <em>The American Statistician</em>, <b>38</b>, 32–35. doi: <a href="https://doi.org/10.2307/2683556">10.2307/2683556</a>. </p> <p>Emerson, J. W. (1998). Mosaic displays in S-PLUS: A general implementation and a case study. <em>Statistical Computing and Graphics Newsletter (ASA)</em>, <b>9</b>, 1, 17–23. </p> <p>Friendly, M. (1994). Mosaic displays for multi-way contingency tables. <em>Journal of the American Statistical Association</em>, <b>89</b>, 190–200. doi: <a href="https://doi.org/10.2307/2291215">10.2307/2291215</a>. </p> <p>Meyer, D., Zeileis, A., and Hornik, K. (2006) The strucplot Framework: Visualizing Multi-Way Contingency Tables with <span class="pkg">vcd</span>. <em>Journal of Statistical Software</em>, <b>17(3)</b>, 1–48. doi: <a href="https://doi.org/10.18637/jss.v017.i03">10.18637/jss.v017.i03</a>. </p> <h3>See Also</h3> <p><code><a href="assocplot.html">assocplot</a></code>, <code><a href="../../stats/html/loglin.html">loglin</a></code>. </p> <h3>Examples</h3> <pre> require(stats) mosaicplot(Titanic, main = "Survival on the Titanic", color = TRUE) ## Formula interface for tabulated data: mosaicplot(~ Sex + Age + Survived, data = Titanic, color = TRUE) mosaicplot(HairEyeColor, shade = TRUE) ## Independence model of hair and eye color and sex. Indicates that ## there are more blue eyed blonde females than expected in the case ## of independence and too few brown eyed blonde females. ## The corresponding model is: fm <- loglin(HairEyeColor, list(1, 2, 3)) pchisq(fm$pearson, fm$df, lower.tail = FALSE) mosaicplot(HairEyeColor, shade = TRUE, margin = list(1:2, 3)) ## Model of joint independence of sex from hair and eye color. Males ## are underrepresented among people with brown hair and eyes, and are ## overrepresented among people with brown hair and blue eyes. ## The corresponding model is: fm <- loglin(HairEyeColor, list(1:2, 3)) pchisq(fm$pearson, fm$df, lower.tail = FALSE) ## Formula interface for raw data: visualize cross-tabulation of numbers ## of gears and carburettors in Motor Trend car data. mosaicplot(~ gear + carb, data = mtcars, color = TRUE, las = 1) # color recycling mosaicplot(~ gear + carb, data = mtcars, color = 2:3, las = 1) </pre> <hr /><div style="text-align: center;">[Package <em>graphics</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>