EVOLUTION-MANAGER
Edit File: spineplot.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: Spine Plots and Spinograms</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 spineplot {graphics}"><tr><td>spineplot {graphics}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Spine Plots and Spinograms</h2> <h3>Description</h3> <p>Spine plots are a special cases of mosaic plots, and can be seen as a generalization of stacked (or highlighted) bar plots. Analogously, spinograms are an extension of histograms. </p> <h3>Usage</h3> <pre> spineplot(x, ...) ## Default S3 method: spineplot(x, y = NULL, breaks = NULL, tol.ylab = 0.05, off = NULL, ylevels = NULL, col = NULL, main = "", xlab = NULL, ylab = NULL, xaxlabels = NULL, yaxlabels = NULL, xlim = NULL, ylim = c(0, 1), axes = TRUE, ...) ## S3 method for class 'formula' spineplot(formula, data = NULL, breaks = NULL, tol.ylab = 0.05, off = NULL, ylevels = NULL, col = NULL, main = "", xlab = NULL, ylab = NULL, xaxlabels = NULL, yaxlabels = NULL, xlim = NULL, ylim = c(0, 1), axes = TRUE, ..., subset = NULL, drop.unused.levels = FALSE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>an object, the default method expects either a single variable (interpreted to be the explanatory variable) or a 2-way table. See details.</p> </td></tr> <tr valign="top"><td><code>y</code></td> <td> <p>a <code>"factor"</code> interpreted to be the dependent variable</p> </td></tr> <tr valign="top"><td><code>formula</code></td> <td> <p>a <code>"formula"</code> of type <code>y ~ x</code> with a single dependent <code>"factor"</code> and a single explanatory variable.</p> </td></tr> <tr valign="top"><td><code>data</code></td> <td> <p>an optional data frame.</p> </td></tr> <tr valign="top"><td><code>breaks</code></td> <td> <p>if the explanatory variable is numeric, this controls how it is discretized. <code>breaks</code> is passed to <code><a href="hist.html">hist</a></code> and can be a list of arguments.</p> </td></tr> <tr valign="top"><td><code>tol.ylab</code></td> <td> <p>convenience tolerance parameter for y-axis annotation. If the distance between two labels drops under this threshold, they are plotted equidistantly.</p> </td></tr> <tr valign="top"><td><code>off</code></td> <td> <p>vertical offset between the bars (in per cent). It is fixed to <code>0</code> for spinograms and defaults to <code>2</code> for spine plots.</p> </td></tr> <tr valign="top"><td><code>ylevels</code></td> <td> <p>a character or numeric vector specifying in which order the levels of the dependent variable should be plotted.</p> </td></tr> <tr valign="top"><td><code>col</code></td> <td> <p>a vector of fill colors of the same length as <code>levels(y)</code>. The default is to call <code><a href="../../grDevices/html/gray.colors.html">gray.colors</a></code>.</p> </td></tr> <tr valign="top"><td><code>main, xlab, ylab</code></td> <td> <p>character strings for annotation</p> </td></tr> <tr valign="top"><td><code>xaxlabels, yaxlabels</code></td> <td> <p>character vectors for annotation of x and y axis. Default to <code>levels(y)</code> and <code>levels(x)</code>, respectively for the spine plot. For <code>xaxlabels</code> in the spinogram, the breaks are used.</p> </td></tr> <tr valign="top"><td><code>xlim, ylim</code></td> <td> <p>the range of x and y values with sensible defaults.</p> </td></tr> <tr valign="top"><td><code>axes</code></td> <td> <p>logical. If <code>FALSE</code> all axes (including those giving level names) are suppressed.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>additional arguments passed to <code><a href="rect.html">rect</a></code>.</p> </td></tr> <tr valign="top"><td><code>subset</code></td> <td> <p>an optional vector specifying a subset of observations to be used for plotting.</p> </td></tr> <tr valign="top"><td><code>drop.unused.levels</code></td> <td> <p>should factors have unused levels dropped? Defaults to <code>FALSE</code>.</p> </td></tr> </table> <h3>Details</h3> <p><code>spineplot</code> creates either a spinogram or a spine plot. It can be called via <code>spineplot(x, y)</code> or <code>spineplot(y ~ x)</code> where <code>y</code> is interpreted to be the dependent variable (and has to be categorical) and <code>x</code> the explanatory variable. <code>x</code> can be either categorical (then a spine plot is created) or numerical (then a spinogram is plotted). Additionally, <code>spineplot</code> can also be called with only a single argument which then has to be a 2-way table, interpreted to correspond to <code>table(x, y)</code>. </p> <p>Both, spine plots and spinograms, are essentially mosaic plots with special formatting of spacing and shading. Conceptually, they plot <i>P(y | x)</i> against <i>P(x)</i>. For the spine plot (where both <i>x</i> and <i>y</i> are categorical), both quantities are approximated by the corresponding empirical relative frequencies. For the spinogram (where <i>x</i> is numerical), <i>x</i> is first discretized (by calling <code><a href="hist.html">hist</a></code> with <code>breaks</code> argument) and then empirical relative frequencies are taken. </p> <p>Thus, spine plots can also be seen as a generalization of stacked bar plots where not the heights but the widths of the bars corresponds to the relative frequencies of <code>x</code>. The heights of the bars then correspond to the conditional relative frequencies of <code>y</code> in every <code>x</code> group. Analogously, spinograms extend stacked histograms. </p> <h3>Value</h3> <p>The table visualized is returned invisibly. </p> <h3>Author(s)</h3> <p>Achim Zeileis <a href="mailto:Achim.Zeileis@R-project.org">Achim.Zeileis@R-project.org</a> </p> <h3>References</h3> <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>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>Hofmann, H., Theus, M. (2005), <em>Interactive graphics for visualizing conditional distributions</em>. Unpublished Manuscript. </p> <p>Hummel, J. (1996). Linked bar charts: Analysing categorical data graphically. <em>Computational Statistics</em>, <b>11</b>, 23–33. </p> <h3>See Also</h3> <p><code><a href="mosaicplot.html">mosaicplot</a></code>, <code><a href="hist.html">hist</a></code>, <code><a href="cdplot.html">cdplot</a></code> </p> <h3>Examples</h3> <pre> ## treatment and improvement of patients with rheumatoid arthritis treatment <- factor(rep(c(1, 2), c(43, 41)), levels = c(1, 2), labels = c("placebo", "treated")) improved <- factor(rep(c(1, 2, 3, 1, 2, 3), c(29, 7, 7, 13, 7, 21)), levels = c(1, 2, 3), labels = c("none", "some", "marked")) ## (dependence on a categorical variable) (spineplot(improved ~ treatment)) ## applications and admissions by department at UC Berkeley ## (two-way tables) (spineplot(margin.table(UCBAdmissions, c(3, 2)), main = "Applications at UCB")) (spineplot(margin.table(UCBAdmissions, c(3, 1)), main = "Admissions at UCB")) ## NASA space shuttle o-ring failures fail <- factor(c(2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1), levels = c(1, 2), labels = c("no", "yes")) temperature <- c(53, 57, 58, 63, 66, 67, 67, 67, 68, 69, 70, 70, 70, 70, 72, 73, 75, 75, 76, 76, 78, 79, 81) ## (dependence on a numerical variable) (spineplot(fail ~ temperature)) (spineplot(fail ~ temperature, breaks = 3)) (spineplot(fail ~ temperature, breaks = quantile(temperature))) ## highlighting for failures spineplot(fail ~ temperature, ylevels = 2: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>