balloonplot.html
9.04 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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>R: Plot a graphical matrix where each cell contains a dot whose size
reflects the relative magnitude of the corresponding component.</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 balloonplot {gplots}"><tr><td>balloonplot {gplots}</td><td align="right">R Documentation</td></tr></table>
<h2>Plot a graphical matrix where each cell contains a dot whose size
reflects the relative magnitude of the corresponding component.</h2>
<h3>Description</h3>
<p>
Plot a graphical matrix where each cell contains a dot whose size
reflects the relative magnitude of the corresponding component.
</p>
<h3>Usage</h3>
<pre>
balloonplot(x, ...)
## S3 method for class 'table':
balloonplot(x, xlab, ylab, zlab, show.zeros=FALSE,show.margins=TRUE,...)
## Default S3 method:
balloonplot(x,y,z,
xlab,
ylab,
zlab=deparse(substitute(z)),
dotsize=2/max(strwidth(19),strheight(19)),
dotchar=19,
dotcolor="skyblue",
main,
label=TRUE,
label.digits=2,
scale.method=c("volume","diameter"),
colsrt=par("srt"),
rowsrt=par("srt"),
colmar=1,
rowmar=2,
show.zeros=FALSE,
show.margins=TRUE,
cum.margins=TRUE,
sorted=TRUE,
label.lines=TRUE,
fun=function(x)sum(x,na.rm=T),
hide.duplicates=TRUE,
... )
</pre>
<h3>Arguments</h3>
<table summary="R argblock">
<tr valign="top"><td><code>x</code></td>
<td>
A table object, or either a vector or a list of several
categorical vectors containing grouping variables for the first
(x) margin of the plotted matrix.</td></tr>
<tr valign="top"><td><code>y</code></td>
<td>
Vector or list of vectors for grouping variables for the
second (y) dimension of the plotted matrix.</td></tr>
<tr valign="top"><td><code>z</code></td>
<td>
Vector of values for the size of the dots in the plotted matrix.</td></tr>
<tr valign="top"><td><code>xlab</code></td>
<td>
Text label for the x dimension. This will be displayed on the
x axis and in the plot title.</td></tr>
<tr valign="top"><td><code>ylab</code></td>
<td>
Text label for the y dimension. This will be displayed on the
y axis and in the plot title.</td></tr>
<tr valign="top"><td><code>zlab</code></td>
<td>
Text label for the dot size. This will be included in the
plot title.</td></tr>
<tr valign="top"><td><code>dotsize</code></td>
<td>
Maximum dot size. You may need to adjust this value
for different plot devices and layouts.</td></tr>
<tr valign="top"><td><code>dotchar</code></td>
<td>
Plotting symbol or character used for dots. See the help
page for the points function for symbol codes.</td></tr>
<tr valign="top"><td><code>dotcolor</code></td>
<td>
Scalar or vector specifying the color(s) of the dots in
the plot.</td></tr>
<tr valign="top"><td><code>main</code></td>
<td>
Plot title text.</td></tr>
<tr valign="top"><td><code>label</code></td>
<td>
Boolean flag indicating whether the actual value of the
elements should be shown on the plot.</td></tr>
<tr valign="top"><td><code>label.digits</code></td>
<td>
Number of digits used in formatting value labels.</td></tr>
<tr valign="top"><td><code>scale.method</code></td>
<td>
Method of scaling the sizes of the dot, either
"volume" or "diameter". See below.</td></tr>
<tr valign="top"><td><code>rowsrt, colsrt</code></td>
<td>
Angle of rotation for row and column labels.</td></tr>
<tr valign="top"><td><code>rowmar, colmar</code></td>
<td>
Space allocated for row and column labels. Each
unit is the width/height of one cell in the table.</td></tr>
<tr valign="top"><td><code>show.zeros</code></td>
<td>
boolean. If <code>FALSE</code>, entries containing zero will be left
blank in the plotted matrix. If <code>TRUE</code>, zeros will be
displayed.</td></tr>
<tr valign="top"><td><code>show.margins</code></td>
<td>
boolean. If <code>TRUE</code>, row and column sums are
printed in the bottom and right margins, respectively.</td></tr>
<tr valign="top"><td><code>cum.margins</code></td>
<td>
boolean. If <code>TRUE</code>, marginal fractions are
graphically presented in grey behind the row/column label area.</td></tr>
<tr valign="top"><td><code>sorted</code></td>
<td>
boolean. If <code>TRUE</code>, the rows will be
arranged in sorted order by using the levels of the first y factor,
then the second y factor, etc. The same process is used for the
columns, based on the x factors</td></tr>
<tr valign="top"><td><code>label.lines</code></td>
<td>
boolean. If <code>TRUE</code>, borders will be drawn for
row and column level headers.</td></tr>
<tr valign="top"><td><code>hide.duplicates</code></td>
<td>
boolean. If <code>TRUE</code>, column and row headers
will omit duplicates within row/column to reduce clutter. Defaults
to <code>TRUE</code>.</td></tr>
<tr valign="top"><td><code>fun</code></td>
<td>
function to be used to combine data elements with the same
levels of the grouping variables <code>x</code> and <code>y</code>. Defaults to <code>sum</code></td></tr>
<tr valign="top"><td><code>...</code></td>
<td>
Additional arguments passed to <code>balloonplot.default</code>
or <code>plot</code>, as appropriate.</td></tr>
</table>
<h3>Details</h3>
<p>
This function plots a visual matrix. In each <code>x</code>,<code>y</code> cell a
dot is plotted which reflects the relative size of the corresponding
value of <code>z</code>. When <code>scale.method="volume"</code> the volume of
the dot is proportional to the relative size of <code>z</code>. When
<code>scale.method="diameter"</code>, the diameter of the dot is proportional to
the the relative size of <code>z</code>. The "volume" method is default
because the "diameter" method visually exaggerates differences.
</p>
<h3>Value</h3>
<p>
Nothing of interest.</p>
<h3>Note</h3>
<p>
<code>z</code> is expected to be non-negative. The function will still
operate correctly if there are negative values of <code>z</code>, but the
corresponding dots will have 0 size and a warning will be generated.
</p>
<h3>Author(s)</h3>
<p>
Gregory R. Warnes <a href="mailto:warnes@bst.rochester.edu">warnes@bst.rochester.edu</a>
</p>
<h3>References</h3>
<p>
Function inspired by question posed on R-help by Ramon
Alonso-Allende <a href="mailto:allende@cnb.uam.es">allende@cnb.uam.es</a>.
</p>
<h3>See Also</h3>
<p>
<code><a href="../../graphics/html/plot.table.html">plot.table</a></code>
</p>
<h3>Examples</h3>
<pre>
# Create an Example Data Frame Containing Car x Color data
carnames <- c("bmw","renault","mercedes","seat")
carcolors <- c("red","white","silver","green")
datavals <- round(rnorm(16, mean=100, sd=60),1)
data <- data.frame(Car=rep(carnames,4),
Color=rep(carcolors, c(4,4,4,4) ),
Value=datavals )
# show the data
data
# generate balloon plot with default scaling
balloonplot( data$Car, data$Color, data$Value)
# show margin label rotation & space expansion, using some long labels
levels(data$Car) <- c("BMW: High End, German","Renault: Medium End, French",
"Mercedes: High End, German", "Seat: Imaginary, Unknown Producer")
# generate balloon plot with default scaling
balloonplot( data$Car, data$Color, data$Value, colmar=3, colsrt=90)
# Create an example using table
xnames <- sample( letters[1:3], 50, replace=2)
ynames <- sample( 1:5, 50, replace=2)
tab <- table(xnames, ynames)
balloonplot(tab)
# Example of multiple classification variabls using the Titanic data
library(datasets)
data(Titanic)
dframe <- as.data.frame(Titanic) # convert to 1 entry per row format
attach(dframe)
balloonplot(x=Class, y=list(Survived, Age, Sex), z=Freq, sort=TRUE)
# colorize: surviors lightblue, non-survivors: grey
Colors <- Titanic
Colors[,,,"Yes"] <- "skyblue"
Colors[,,,"No"] <- "grey"
colors <- as.character(as.data.frame(Colors)$Freq)
balloonplot(x=list(Age,Sex),
y=list(Class=Class,
Survived=reorder.factor(Survived,c(2,1))),
z=Freq,
zlab="Number of Passengers",
sort=TRUE,
dotcol = colors,
show.zeros=TRUE,
show.margins=TRUE)
</pre>
<hr><div align="center">[Package <em>gplots</em> version 2.3.2 <a href="00Index.html">Index]</a></div>
</body></html>