ooplot.html
13.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<!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 <- cbind( Age=c(50,55,60,65,70), VADeaths)
mp <- ooplot(VADeaths) # default
mp <- ooplot(VADeaths, type="xyplot") # same as default
mp <- ooplot(VADeaths, type="linear") # linear scale
mp <- ooplot(VADeaths, type="linear", log="y") # log scale on y axis
mp <- ooplot(VADeaths, type="barplot") # barplot
mp <- ooplot(VADeaths, type="stackbar") # stacked
tot <- 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 <- data.frame(x=c(0,1,2,3,4), lin=c(0,1,2,3,4))
test2 <- data.frame(x=c(0,1,2,3,4), par=c(0,1,4,9,16))
test3 <- data.frame(x=c(-2,-1,0,1,2),y2=c(4,1,0,1,4))
## single line test example
test1f <- test1
## two column example
test2f <- merge(test1,test2,by.x="x",all=TRUE,sort=TRUE)
## three column example
test3f <- merge(test2f,test3,by.x="x",all=TRUE,sort=TRUE)
## subset, single row, example
test5r <- test3f[5,]
##
## xyplot, linear, barplot, stackbar
mat <- 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>