ooplot.html 13.6 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>R: Create an OpenOffice style plot</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 ooplot.default {gplots}"><tr><td>ooplot.default {gplots}</td><td align="right">R Documentation</td></tr></table>
<h2>Create an OpenOffice style plot</h2>


<h3>Description</h3>

<p>
An extension of barplot2. Creates bar- and line-plots mimicking the
style of OpenOffice plots.  This utility can plot the values next to
each point or bar as well as confidence intervals.
</p>


<h3>Usage</h3>

<pre>
ooplot(data, ...)
ooplot.default(data, width=1, space=NULL, names.arg=NULL, 
                           legend.text=NULL, horiz=FALSE, 
                           density=NULL, angle=45, kmg="fpnumkMGTP", 
                           kmglim=TRUE, 
                           type=c("xyplot", "linear", "barplot", "stackbar"), 
                           col=heat.colors(NC), prcol=NULL, 
                           border=par("fg"), main=NULL, sub=NULL, 
                           xlab=NULL, ylab=NULL, xlim=NULL, ylim=NULL, 
                           xpd=TRUE, log="", axes=TRUE, 
                           axisnames=TRUE, prval=TRUE, lm=FALSE,
                           cex.axis=par("cex.axis"), 
                           cex.names=par("cex.axis"),
                           cex.values=par("cex"),inside=TRUE, 
                           plot=TRUE, axis.lty=0, plot.ci=FALSE, 
                           ci.l=NULL, ci.u=NULL, ci.color="black", 
                           ci.lty="solid", ci.lwd=1, plot.grid=FALSE, 
                           grid.inc=NULL, grid.lty="dotted", 
                           grid.lwd=1, grid.col="black", add=FALSE, 
                           by.row=FALSE, ...)
</pre>


<h3>Arguments</h3>

<table summary="R argblock">
<tr valign="top"><td><code>data</code></td>
<td>
a matrix of values describing the values that make up the
plot. The first column of <code>data</code> is taken as the axis against
which all the other values are plotted. The first column of
<code>data</code> may not be sparse.</td></tr>
<tr valign="top"><td><code>width</code></td>
<td>
optional vector of barwidths. Re-cycled to the number of
bars drawn. A single value will have no visible effect. </td></tr>
<tr valign="top"><td><code>space</code></td>
<td>
the amount of space left before each bar. May be given
as a single number or one number per bar. If <code>type</code> is
<code>stackbar</code>, <code>space</code> may be specified by two numbers, where
the first is the space between bars in the same group, and the second
the space between groups. Defaults to <code>c(0,1)</code> if <code>type</code> is
a <code>stackbar</code>, and to 0.2 otherwise. </td></tr>
<tr valign="top"><td><code>names.arg</code></td>
<td>
a vector of names to be plotted below each bar or
group of bars.  If this argument is omitted, then the names are
taken from the  row names of <code>data</code>. </td></tr>
<tr valign="top"><td><code>legend.text</code></td>
<td>
a vector of text used to construct a legend for the
plot, or a logical indicating whether a legend should be included;
if <code>legend.text</code> is true, the row names of <code>data</code> will
be used as labels if they are non-null.</td></tr>
<tr valign="top"><td><code>horiz</code></td>
<td>
a logical value.  If <code>FALSE</code>, the bars are drawn
vertically with the first bar to the left.  If <code>TRUE</code>, the
bars are drawn horizontally with the first at the bottom.</td></tr>
<tr valign="top"><td><code>density</code></td>
<td>
a vector giving the the density of shading lines, in
lines per inch, for the bars or bar components.
The default value of <code>NULL</code> means that no shading lines
are drawn. Non-positive values of <code>density</code> also inhibit the
drawing of shading lines.</td></tr>
<tr valign="top"><td><code>angle</code></td>
<td>
the slope of shading lines, given as an angle in
degrees (counter-clockwise), for the bars or bar components.</td></tr>
<tr valign="top"><td><code>kmg</code></td>
<td>
the set of SI units to convert, defaults to
"fpnumkMGTP". See below for details. </td></tr>
<tr valign="top"><td><code>kmglim</code></td>
<td>
logical. If <code>FALSE</code> the conversion to SI units is not
performed. Default is <code>TRUE</code>.
</td></tr>
<tr valign="top"><td><code>type</code></td>
<td>
a string indicating the preferred format of the plot,
choices are:
xyplot : plot where y is plotted against the x-value.
linear : plot where y values are plotted against equidistant x-values.
barplot : plot where y values are represented as bars against
equidistant x-values.
stackplot : plot where y values are stacked for identical x-values
and bars are equidistant.
</td></tr>
<tr valign="top"><td><code>col</code></td>
<td>
a vector of colors for the bars or bar components.</td></tr>
<tr valign="top"><td><code>prcol</code></td>
<td>
the color to be used for the plot region.</td></tr>
<tr valign="top"><td><code>border</code></td>
<td>
the color to be used for the border of the bars.</td></tr>
<tr valign="top"><td><code>main, sub</code></td>
<td>
overall and sub titles for the plot.</td></tr>
<tr valign="top"><td><code>xlab</code></td>
<td>
a label for the x axis.</td></tr>
<tr valign="top"><td><code>ylab</code></td>
<td>
a label for the y axis.</td></tr>
<tr valign="top"><td><code>xlim</code></td>
<td>
limits for the x axis.</td></tr>
<tr valign="top"><td><code>ylim</code></td>
<td>
limits for the y axis.</td></tr>
<tr valign="top"><td><code>xpd</code></td>
<td>
logical. Should bars be allowed to go outside region?</td></tr>
<tr valign="top"><td><code>log</code></td>
<td>
a character string which contains `"x"' if the x axis is
to be logarithmic, `"y"' if the y axis is to be logarithmic and
`"xy"' or `"yx"' if both axes are to be logarithmic.</td></tr>
<tr valign="top"><td><code>axes</code></td>
<td>
logical.  If <code>TRUE</code>, a vertical (or horizontal, if
<code>horiz</code> is true) axis is drawn.</td></tr>
<tr valign="top"><td><code>axisnames</code></td>
<td>
logical.  If <code>TRUE</code>, and if there are
<code>names.arg</code> (see above), the
other axis is drawn (with <code>lty=0</code>) and labeled.</td></tr>
<tr valign="top"><td><code>prval</code></td>
<td>
logical. If <code>TRUE</code>, then values are plotted above
all points and bars.
</td></tr>
<tr valign="top"><td><code>lm</code></td>
<td>
logical. If <code>TRUE</code>, the linear fit is plotted.
</td></tr>
<tr valign="top"><td><code>cex.axis, cex.names, cex.values</code></td>
<td>
character scaling factor for
numeric axis labels,
names, and displayed values, respectively.</td></tr>
<tr valign="top"><td><code>inside</code></td>
<td>
logical.  If <code>TRUE</code>, the lines which divide
adjacent (non-stacked!) bars will be drawn.  Only applies when
<code>space = 0</code> (which it partly is when <code>beside = TRUE</code>).</td></tr>
<tr valign="top"><td><code>plot</code></td>
<td>
logical.  If <code>FALSE</code>, nothing is plotted.</td></tr>
<tr valign="top"><td><code>axis.lty</code></td>
<td>
the graphics parameter <code>lty</code> applied to the axis
and tick marks of the categorical (default horzontal) axis.  Note
that by default the axis is suppressed.</td></tr>
<tr valign="top"><td><code>plot.ci</code></td>
<td>
logical. If <code>TRUE</code>, confidence intervals are plotted
over the bars. Note that if a stacked bar plot is generated, confidence
intervals will not be plotted even if <code>plot.ci = TRUE</code></td></tr>
<tr valign="top"><td><code>ci.l,ci.u</code></td>
<td>
The confidence intervals (ci.l = lower bound, ci.u =
upper bound) to be plotted if <code>plot.ci</code> = <code>TRUE</code>. Values must have
the same dim structure as <code>height</code>.</td></tr>
<tr valign="top"><td><code>ci.color</code></td>
<td>
the color for the confidence interval line segments</td></tr>
<tr valign="top"><td><code>ci.lty</code></td>
<td>
the line type for the confidence interval line segments</td></tr>
<tr valign="top"><td><code>ci.lwd</code></td>
<td>
the line width for the confidence interval line segments</td></tr>
<tr valign="top"><td><code>plot.grid</code></td>
<td>
if <code>TRUE</code> a lined grid will be plotted behind the bars</td></tr>
<tr valign="top"><td><code>grid.inc</code></td>
<td>
the number of grid increments to be plotted</td></tr>
<tr valign="top"><td><code>grid.lty</code></td>
<td>
the line type for the grid</td></tr>
<tr valign="top"><td><code>grid.lwd</code></td>
<td>
the line width for the grid</td></tr>
<tr valign="top"><td><code>grid.col</code></td>
<td>
the line color for the grid</td></tr>
<tr valign="top"><td><code>add</code></td>
<td>
logical, if <code>TRUE</code> add barplot to current plot.</td></tr>
<tr valign="top"><td><code>by.row</code></td>
<td>
Logical value.  If <code>TRUE</code> the data matrix is
organized with variables along rows rather than down colums.</td></tr>
<tr valign="top"><td><code>...</code></td>
<td>
further graphical parameters (<code><a href="../../graphics/html/par.html">par</a></code>) are
passed to <code><a href="../../graphics/html/plot.window.html">plot.window</a>()</code>, <code><a href="../../graphics/html/title.html">title</a>()</code> and
<code><a href="../../graphics/html/axis.html">axis</a></code>.</td></tr>
</table>

<h3>Details</h3>

<p>
Plot units are automatically scaled to SI units based on the
maximum value present, according to the set of units specified by
characters in the <code>kmg</code> parameter.  These letters are interpreted
as
<dl>
<dt>P</dt><dd>peta = 1E15</dd>
<dt>T</dt><dd>tera = 1E12</dd>
<dt>G</dt><dd>giga = 1E09</dd>
<dt>M</dt><dd>mega = 1E06</dd>
<dt>k</dt><dd>kilo = 1E03</dd>
<dt>m</dt><dd>milli= 1E-03</dd>
<dt>u</dt><dd>micro= 1E-06</dd>
<dt>n</dt><dd>nano = 1E-09</dd>
<dt>p</dt><dd>pico = 1E-12</dd>
<dt>f</dt><dd>femto= 1E-15</dd>
</dl>
<p>
with the default being "fpnumkMGTP" (all of these units).  For
example, if the largest value plotted is 1243000, it would be
presented as 1.234M.
</p>


<h3>Value</h3>

<p>
A numeric vector (or matrix, when <code>beside = TRUE</code>), say
<code>mp</code>, giving the coordinates of <EM>all</EM> the bar midpoints
drawn, useful for adding to the graph.
<br>
If <code>beside</code> is true, use <code>colMeans(mp)</code> for the
midpoints of each <EM>group</EM> of bars, see example.</p>

<h3>Author(s)</h3>

<p>
Lodewijk Bonebakker <a href="mailto:bonebakker@comcast.net">bonebakker@comcast.net</a> with modifications
by Gregory R. Warnes <a href="mailto:warnes@bst.rochester.edu">warnes@bst.rochester.edu</a>.
Based on barplot2().
</p>


<h3>See Also</h3>

<p>
<code><a href="../../plot/html/plot.html">plot</a></code>, <code><a href="../../plot/html/boxplot.html">boxplot</a></code>
</p>


<h3>Examples</h3>

<pre>
     data(VADeaths, package = "base")

     VADeaths &lt;- cbind( Age=c(50,55,60,65,70), VADeaths)

     mp &lt;- ooplot(VADeaths) # default
     mp &lt;- ooplot(VADeaths, type="xyplot")  # same as default
     mp &lt;- ooplot(VADeaths, type="linear")  # linear scale
     mp &lt;- ooplot(VADeaths, type="linear", log="y") # log scale on y axis
     mp &lt;- ooplot(VADeaths, type="barplot") # barplot
     mp &lt;- ooplot(VADeaths, type="stackbar") # stacked

     tot &lt;- colMeans(VADeaths[,-1])
     ooplot(VADeaths, 
             col = c("lightblue", "mistyrose", "lightcyan", "lavender"),
             legend = colnames(VADeaths)[-1], ylim = c(0, 100),
             type="barplot", cex.values=0.75)
     title(main = "Death Rates in Virginia", font.main = 4)

     ##
     ## Capability demo
     ##
     ## examples for the ooplot routine
     ##
     ## create some test data
     test1 &lt;- data.frame(x=c(0,1,2,3,4), lin=c(0,1,2,3,4))
     test2 &lt;- data.frame(x=c(0,1,2,3,4), par=c(0,1,4,9,16))
     test3 &lt;- data.frame(x=c(-2,-1,0,1,2),y2=c(4,1,0,1,4))
     ## single line test example
     test1f &lt;- test1
     ## two column example
     test2f &lt;- merge(test1,test2,by.x="x",all=TRUE,sort=TRUE)
     ## three column example
     test3f &lt;- merge(test2f,test3,by.x="x",all=TRUE,sort=TRUE)
     ## subset, single row, example
     test5r &lt;- test3f[5,]  
     
     ##
     ## xyplot, linear, barplot, stackbar
     mat &lt;- matrix(c(1:16),4,4,byrow=TRUE)
     layout(mat)
     
     ooplot(test1f,type="barplot",col=c("red"))
     title(main="barplot")
     ooplot(test2f,type="barplot",col=c("red","blue"))
     ooplot(test3f,type="barplot",col=c("red","blue","green"))
     ooplot(test5r,type="barplot",col=c("red","blue","green"))
     
     ooplot(test1f,type="xyplot",col=c("red"))
     title(main="xyplot")
     ooplot(test2f,type="xyplot",col=c("red","blue"))
     ooplot(test3f,type="xyplot",col=c("red","blue","green"))
     ooplot(test5r,type="xyplot",col=c("red","blue","green"))
     
     ooplot(test1f,type="linear",col=c("red"))
     title(main="linear")
     ooplot(test2f,type="linear",col=c("red","blue"))
     ooplot(test3f,type="linear",col=c("red","blue","green"))
     ooplot(test5r,type="linear",col=c("red","blue","green"))
     
     ooplot(test1f,type="stackbar",col=c("red"))
     title(main="stackbar")
     ooplot(test2f,type="stackbar",col=c("red","blue"))
     ooplot(test3f,type="stackbar",col=c("red","blue","green"))
     ooplot(test5r,type="stackbar",col=c("red","blue","green"))

</pre>



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

</body></html>