EVOLUTION-MANAGER
Edit File: boxplot.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: Box 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 boxplot {graphics}"><tr><td>boxplot {graphics}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Box Plots</h2> <h3>Description</h3> <p>Produce box-and-whisker plot(s) of the given (grouped) values. </p> <h3>Usage</h3> <pre> boxplot(x, ...) ## S3 method for class 'formula' boxplot(formula, data = NULL, ..., subset, na.action = NULL, xlab = paste(names(mf)[-response], collapse = " : "), ylab = names(mf)[ response], add = FALSE, ann = !add, drop = FALSE, sep = ".", lex.order = FALSE) ## Default S3 method: boxplot(x, ..., range = 1.5, width = NULL, varwidth = FALSE, notch = FALSE, outline = TRUE, names, plot = TRUE, border = par("fg"), col = NULL, log = "", pars = list(boxwex = 0.8, staplewex = 0.5, outwex = 0.5), ann = !add, horizontal = FALSE, add = FALSE, at = NULL) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>formula</code></td> <td> <p>a formula, such as <code>y ~ grp</code>, where <code>y</code> is a numeric vector of data values to be split into groups according to the grouping variable <code>grp</code> (usually a factor). Note that <code>~ g1 + g2</code> is equivalent to <code>g1:g2</code>.</p> </td></tr> <tr valign="top"><td><code>data</code></td> <td> <p>a data.frame (or list) from which the variables in <code>formula</code> should be taken.</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>na.action</code></td> <td> <p>a function which indicates what should happen when the data contain <code>NA</code>s. The default is to ignore missing values in either the response or the group.</p> </td></tr> <tr valign="top"><td><code>xlab, ylab</code></td> <td> <p>x- and y-axis annotation, since <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> 3.6.0 with a non-empty default. Can be suppressed by <code>ann=FALSE</code>.</p> </td></tr> <tr valign="top"><td><code>ann</code></td> <td> <p><code><a href="../../base/html/logical.html">logical</a></code> indicating if axes should be annotated (by <code>xlab</code> and <code>ylab</code>).</p> </td></tr> <tr valign="top"><td><code>drop, sep, lex.order</code></td> <td> <p>passed to <code><a href="../../base/html/split.html">split.default</a></code>, see there.</p> </td></tr> <tr valign="top"><td><code>x</code></td> <td> <p>for specifying data from which the boxplots are to be produced. Either a numeric vector, or a single list containing such vectors. Additional unnamed arguments specify further data as separate vectors (each corresponding to a component boxplot). <code><a href="../../base/html/NA.html">NA</a></code>s are allowed in the data.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>For the <code>formula</code> method, named arguments to be passed to the default method. </p> <p>For the default method, unnamed arguments are additional data vectors (unless <code>x</code> is a list when they are ignored), and named arguments are arguments and <a href="par.html">graphical parameters</a> to be passed to <code><a href="bxp.html">bxp</a></code> in addition to the ones given by argument <code>pars</code> (and override those in <code>pars</code>). Note that <code>bxp</code> may or may not make use of graphical parameters it is passed: see its documentation. </p> </td></tr> <tr valign="top"><td><code>range</code></td> <td> <p>this determines how far the plot whiskers extend out from the box. If <code>range</code> is positive, the whiskers extend to the most extreme data point which is no more than <code>range</code> times the interquartile range from the box. A value of zero causes the whiskers to extend to the data extremes.</p> </td></tr> <tr valign="top"><td><code>width</code></td> <td> <p>a vector giving the relative widths of the boxes making up the plot.</p> </td></tr> <tr valign="top"><td><code>varwidth</code></td> <td> <p>if <code>varwidth</code> is <code>TRUE</code>, the boxes are drawn with widths proportional to the square-roots of the number of observations in the groups.</p> </td></tr> <tr valign="top"><td><code>notch</code></td> <td> <p>if <code>notch</code> is <code>TRUE</code>, a notch is drawn in each side of the boxes. If the notches of two plots do not overlap this is ‘strong evidence’ that the two medians differ (Chambers <em>et al</em>, 1983, p. 62). See <code><a href="../../grDevices/html/boxplot.stats.html">boxplot.stats</a></code> for the calculations used.</p> </td></tr> <tr valign="top"><td><code>outline</code></td> <td> <p>if <code>outline</code> is not true, the outliers are not drawn (as points whereas S+ uses lines).</p> </td></tr></table> <table summary="R argblock"> <tr valign="top"><td><code>names</code></td> <td> <p>group labels which will be printed under each boxplot. Can be a character vector or an <a href="../../base/html/expression.html">expression</a> (see <a href="../../grDevices/html/plotmath.html">plotmath</a>).</p> </td></tr> <tr valign="top"><td><code>boxwex</code></td> <td> <p>a scale factor to be applied to all boxes. When there are only a few groups, the appearance of the plot can be improved by making the boxes narrower.</p> </td></tr> <tr valign="top"><td><code>staplewex</code></td> <td> <p>staple line width expansion, proportional to box width.</p> </td></tr> <tr valign="top"><td><code>outwex</code></td> <td> <p>outlier line width expansion, proportional to box width.</p> </td></tr> <tr valign="top"><td><code>plot</code></td> <td> <p>if <code>TRUE</code> (the default) then a boxplot is produced. If not, the summaries which the boxplots are based on are returned.</p> </td></tr> <tr valign="top"><td><code>border</code></td> <td> <p>an optional vector of colors for the outlines of the boxplots. The values in <code>border</code> are recycled if the length of <code>border</code> is less than the number of plots.</p> </td></tr> <tr valign="top"><td><code>col</code></td> <td> <p>if <code>col</code> is non-null it is assumed to contain colors to be used to colour the bodies of the box plots. By default they are in the background colour.</p> </td></tr> <tr valign="top"><td><code>log</code></td> <td> <p>character indicating if x or y or both coordinates should be plotted in log scale.</p> </td></tr> <tr valign="top"><td><code>pars</code></td> <td> <p>a list of (potentially many) more graphical parameters, e.g., <code>boxwex</code> or <code>outpch</code>; these are passed to <code><a href="bxp.html">bxp</a></code> (if <code>plot</code> is true); for details, see there.</p> </td></tr> <tr valign="top"><td><code>horizontal</code></td> <td> <p>logical indicating if the boxplots should be horizontal; default <code>FALSE</code> means vertical boxes.</p> </td></tr> <tr valign="top"><td><code>add</code></td> <td> <p>logical, if true <em>add</em> boxplot to current plot.</p> </td></tr> <tr valign="top"><td><code>at</code></td> <td> <p>numeric vector giving the locations where the boxplots should be drawn, particularly when <code>add = TRUE</code>; defaults to <code>1:n</code> where <code>n</code> is the number of boxes.</p> </td></tr> </table> <h3>Details</h3> <p>The generic function <code>boxplot</code> currently has a default method (<code>boxplot.default</code>) and a formula interface (<code>boxplot.formula</code>). </p> <p>If multiple groups are supplied either as multiple arguments or via a formula, parallel boxplots will be plotted, in the order of the arguments or the order of the levels of the factor (see <code><a href="../../base/html/factor.html">factor</a></code>). </p> <p>Missing values are ignored when forming boxplots. </p> <h3>Value</h3> <p>List with the following components: </p> <table summary="R valueblock"> <tr valign="top"><td><code>stats</code></td> <td> <p>a matrix, each column contains the extreme of the lower whisker, the lower hinge, the median, the upper hinge and the extreme of the upper whisker for one group/plot. If all the inputs have the same class attribute, so will this component.</p> </td></tr> <tr valign="top"><td><code>n</code></td> <td> <p>a vector with the number of observations in each group.</p> </td></tr> <tr valign="top"><td><code>conf</code></td> <td> <p>a matrix where each column contains the lower and upper extremes of the notch.</p> </td></tr> <tr valign="top"><td><code>out</code></td> <td> <p>the values of any data points which lie beyond the extremes of the whiskers.</p> </td></tr> <tr valign="top"><td><code>group</code></td> <td> <p>a vector of the same length as <code>out</code> whose elements indicate to which group the outlier belongs.</p> </td></tr> <tr valign="top"><td><code>names</code></td> <td> <p>a vector of names for the groups.</p> </td></tr> </table> <h3>References</h3> <p>Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988). <em>The New S Language</em>. Wadsworth & Brooks/Cole. </p> <p>Chambers, J. M., Cleveland, W. S., Kleiner, B. and Tukey, P. A. (1983). <em>Graphical Methods for Data Analysis</em>. Wadsworth & Brooks/Cole. </p> <p>Murrell, P. (2005). <em>R Graphics</em>. Chapman & Hall/CRC Press. </p> <p>See also <code><a href="../../grDevices/html/boxplot.stats.html">boxplot.stats</a></code>. </p> <h3>See Also</h3> <p><code><a href="../../grDevices/html/boxplot.stats.html">boxplot.stats</a></code> which does the computation, <code><a href="bxp.html">bxp</a></code> for the plotting and more examples; and <code><a href="stripchart.html">stripchart</a></code> for an alternative (with small data sets). </p> <h3>Examples</h3> <pre> ## boxplot on a formula: boxplot(count ~ spray, data = InsectSprays, col = "lightgray") # *add* notches (somewhat funny here): boxplot(count ~ spray, data = InsectSprays, notch = TRUE, add = TRUE, col = "blue") boxplot(decrease ~ treatment, data = OrchardSprays, log = "y", col = "bisque") rb <- boxplot(decrease ~ treatment, data = OrchardSprays, col = "bisque") title("Comparing boxplot()s and non-robust mean +/- SD") mn.t <- tapply(OrchardSprays$decrease, OrchardSprays$treatment, mean) sd.t <- tapply(OrchardSprays$decrease, OrchardSprays$treatment, sd) xi <- 0.3 + seq(rb$n) points(xi, mn.t, col = "orange", pch = 18) arrows(xi, mn.t - sd.t, xi, mn.t + sd.t, code = 3, col = "pink", angle = 75, length = .1) ## boxplot on a matrix: mat <- cbind(Uni05 = (1:100)/21, Norm = rnorm(100), `5T` = rt(100, df = 5), Gam2 = rgamma(100, shape = 2)) boxplot(mat) # directly, calling boxplot.matrix() ## boxplot on a data frame: df. <- as.data.frame(mat) par(las = 1) # all axis labels horizontal boxplot(df., main = "boxplot(*, horizontal = TRUE)", horizontal = TRUE) ## Using 'at = ' and adding boxplots -- example idea by Roger Bivand : boxplot(len ~ dose, data = ToothGrowth, boxwex = 0.25, at = 1:3 - 0.2, subset = supp == "VC", col = "yellow", main = "Guinea Pigs' Tooth Growth", xlab = "Vitamin C dose mg", ylab = "tooth length", xlim = c(0.5, 3.5), ylim = c(0, 35), yaxs = "i") boxplot(len ~ dose, data = ToothGrowth, add = TRUE, boxwex = 0.25, at = 1:3 + 0.2, subset = supp == "OJ", col = "orange") legend(2, 9, c("Ascorbic acid", "Orange juice"), fill = c("yellow", "orange")) ## With less effort (slightly different) using factor *interaction*: boxplot(len ~ dose:supp, data = ToothGrowth, boxwex = 0.5, col = c("orange", "yellow"), main = "Guinea Pigs' Tooth Growth", xlab = "Vitamin C dose mg", ylab = "tooth length", sep = ":", lex.order = TRUE, ylim = c(0, 35), yaxs = "i") ## more examples in help(bxp) </pre> <hr /><div style="text-align: center;">[Package <em>graphics</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>