plotCI.html 6.13 KB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><title>R: Plot Error Bars and Confidence Intervals</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../../R.css">
</head><body>

<table width="100%" summary="page for plotCI {gplots}"><tr><td>plotCI {gplots}</td><td align="right">R Documentation</td></tr></table>
<h2>Plot Error Bars and Confidence Intervals</h2>


<h3>Description</h3>

<p>
Given a set of x and y values and interval width or upper and lower bounds,
plot the points with error bars.  This can be a useful tool for
visualizing confidence intervals.
</p>


<h3>Usage</h3>

<pre>
plotCI(x, y = NULL, uiw, liw = uiw, ui, li, err='y', ylim=NULL,
       xlim=NULL, type="p",  col=par("col"), barcol=col,
       pt.bg = par("bg"),  sfrac = 0.01, gap=1, lwd=par("lwd"),
       lty=par("lty"), labels=FALSE, add=FALSE, xlab, ylab,  minbar,
       maxbar, ... )
</pre>


<h3>Arguments</h3>

<table summary="R argblock">
<tr valign="top"><td><code>x,y</code></td>
<td>
coordinates for the center of error bars. <code>y</code>
defaults to <code>1:n</code>.</td></tr>
<tr valign="top"><td><code>uiw</code></td>
<td>
width of the upper or right error bar. Set to <code>NULL</code>
omit upper bars.</td></tr>
<tr valign="top"><td><code>liw</code></td>
<td>
width of the lower or left error bar.  Defaults to same value as
<code>uiw</code>.  Set to <code>NULL</code> to omit lower bars. </td></tr>
<tr valign="top"><td><code>ui</code></td>
<td>
upper end of error bars.  Defaults to <code>y + uiw</code> or
<code>x + uiw</code> depeding on <code>err</code>.  Set to <code>NULL</code> omit
upper bars. </td></tr>
<tr valign="top"><td><code>li</code></td>
<td>
lower end of error bars.  Defaults to <code>y - liw</code> or
<code>x - liw</code> depedning on <code>err</code>.  Set to <code>NULL</code> to omit
lower bars.</td></tr>
<tr valign="top"><td><code>err</code></td>
<td>
direction for error bars. Set to "y" for vertical bars.
Set to "x" for horizontal bars. Defaults to "y".</td></tr>
<tr valign="top"><td><code>col</code></td>
<td>
color of plotting character used center marker of error
bars. Default is "black".</td></tr>
<tr valign="top"><td><code>xlim, ylim</code></td>
<td>
range of x/y values to include in the plotting area. </td></tr>
<tr valign="top"><td><code>type</code></td>
<td>
point/line type; passed to <code><a href="../../graphics/html/points.html">points</a></code></td></tr>
<tr valign="top"><td><code>barcol</code></td>
<td>
color of the error bars.  Defaults to the same value as
<code>col</code> </td></tr>
<tr valign="top"><td><code>pt.bg</code></td>
<td>
background color of points (use
<code>pch=21, pt.bg=par("bg")</code> to get open points superimposed on
error bars).</td></tr>
<tr valign="top"><td><code>sfrac</code></td>
<td>
width of "crossbar" at the end of error bar as a fraction
of the x plotting region. Defaults to 0.01. </td></tr>
<tr valign="top"><td><code>gap</code></td>
<td>
space left between the center of the error bar and the
lines marking the error bar in units of the height (width) of the
letter "O".  Defaults to 1.0 </td></tr>
<tr valign="top"><td><code>lwd</code></td>
<td>
width of bar lines. </td></tr>
<tr valign="top"><td><code>lty</code></td>
<td>
line type of bar lines. </td></tr>
<tr valign="top"><td><code>labels</code></td>
<td>
either a logical value indicating whether the circles
representing the x values should be replaced with text giving the
actual values or a vector containing labels to use
instead. Defaults to <code>FALSE</code>. </td></tr>
<tr valign="top"><td><code>add</code></td>
<td>
logical indicating whether error bars should be added to
the current plot.  If <code>FALSE</code> (the defailt), a new plot will be
created and symbols/labels for the x values will be plotted before
drawing error bars.</td></tr>
<tr valign="top"><td><code>minbar</code></td>
<td>
minumum allowed value for bar ends.  If specified,
values smaller than <code>minbar</code> will be replaced with
<code>minbar</code>. </td></tr>
<tr valign="top"><td><code>maxbar</code></td>
<td>
maximum allowed value for bar ends.  If specified,
values larger than <code>maxbar</code> will be replaced with
<code>maxbar</code>. </td></tr>
<tr valign="top"><td><code>...</code></td>
<td>
optional plotting parameters </td></tr>
<tr valign="top"><td><code>xlab</code></td>
<td>
label for x axis. </td></tr>
<tr valign="top"><td><code>ylab</code></td>
<td>
label for y axis. </td></tr>
</table>

<h3>Author(s)</h3>

<p>
Original version by Bill Venables
<a href="mailto:wvenable@attunga.stats.adelaide.edu.au">wvenable@attunga.stats.adelaide.edu.au</a> posted to r-help on
Sep. 20, 1997.  Enhanced version posted to r-help by Ben Bolker
<a href="mailto:ben@zoo.ufl.edu">ben@zoo.ufl.edu</a> on Apr. 16, 2001.  This version was modified
and extended by Gregory R. Warnes
<a href="mailto:warnes@bst.rochester.edu">warnes@bst.rochester.edu</a>.  Additional changes
suggested by Martin Maechler <a href="mailto:maechler@stat.math.ethz.ch">maechler@stat.math.ethz.ch</a>
integrated on July 29, 2004.
</p>


<h3>See Also</h3>

<p>
<code><a href="plotmeans.html">plotmeans</a></code> provides an enhanced wrapper to
<code>plotCI</code>.
</p>


<h3>Examples</h3>

<pre>

  # plot means and
  data(state)
  tmp   &lt;- split(state.area, state.region)
  means &lt;- sapply(tmp, mean)
  stdev &lt;- sqrt(sapply(tmp, var))
  n     &lt;- sapply(tmp,length)
  ciw   &lt;- qt(0.975, n) * stdev / sqrt(n)

  # plain
  plotCI(x=means, uiw=ciw)

  # prettier
  plotCI(x=means, uiw=ciw, col="black", barcol="blue", lwd=1)

  # give mean values
  plotCI(x=means, uiw=ciw, col="black", barcol="blue",
         labels=round(means,-3), xaxt="n", xlim=c(0,5) )
  axis(side=1, at=1:4, labels=names(tmp), cex=0.7)

  # better yet, just use plotmeans ... #
  plotmeans( state.area ~ state.region )

</pre>



<hr><div align="center">[Package <em>gplots</em> version 2.3.2 <a href="00Index.html">Index]</a></div>

</body></html>