-
Notifications
You must be signed in to change notification settings - Fork 8
/
drape.plot.html
234 lines (192 loc) · 7.75 KB
/
drape.plot.html
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
<!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: Perspective plot draped with colors in the facets.</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 drape.plot {fields}"><tr><td>drape.plot {fields}</td><td style="text-align: right;">R Documentation</td></tr></table>
<h2>Perspective plot draped with colors in the facets.</h2>
<h3>Description</h3>
<p>Function to produce the
usual wireframe perspective plot with the facets being filled
with different colors. By default the colors are assigned from a
color bar based on the z values. <code>drape.color</code> can be used to create
a color matrix different from the z matrix used for the wireframe.</p>
<h3>Usage</h3>
<pre>
drape.plot(x, y, z, z2=NULL, col = tim.colors(64), zlim = range(z, na.rm=TRUE),
zlim2 = NULL, add.legend = TRUE, horizontal = TRUE, theta = 30, phi = 20,
breaks=NA, ...)
drape.color(z, col = tim.colors(64), zlim = NULL,breaks,
transparent.color = "white", midpoint=TRUE, eps=1e-8)
</pre>
<h3>Arguments</h3>
<table summary="R argblock">
<tr valign="top"><td><code>x</code></td>
<td>
<p> grid values for x coordinate (or if x is a list the
components x y and z are used.)</p>
</td></tr>
<tr valign="top"><td><code>y</code></td>
<td>
<p>grid values for y coordinate</p>
</td></tr>
<tr valign="top"><td><code>z</code></td>
<td>
<p>A matrix of z heights </p>
</td></tr>
<tr valign="top"><td><code>z2</code></td>
<td>
<p> A matrix of z values to use for coloring facets. If NULL
then z is used for this purpose</p>
</td></tr>
<tr valign="top"><td><code>col</code></td>
<td>
<p> A color table for the z values that will be used for draping</p>
</td></tr>
<tr valign="top"><td><code>zlim</code></td>
<td>
<p>the z limits for <code>z</code> these are used to set up
the scale of the persp plot. This defaults to range(z, na.rm=TRUE) as
in persp</p>
</td></tr>
<tr valign="top"><td><code>zlim2</code></td>
<td>
<p>the z limits for <code>z2</code> these are used to set up
the color scale. This defaults to </p>
</td></tr>
<tr valign="top"><td><code>add.legend</code></td>
<td>
<p> If true a color strip is added as a legend.</p>
</td></tr>
<tr valign="top"><td><code>horizontal</code></td>
<td>
<p> If true color strip is put at bottom of the
plot, if FALSE it is placed vertically on the right side. </p>
</td></tr>
<tr valign="top"><td><code>theta</code></td>
<td>
<p> x-y rotation angle for perspective. </p>
</td></tr>
<tr valign="top"><td><code>phi</code></td>
<td>
<p> z-angle for perspective. </p>
</td></tr>
<tr valign="top"><td><code>transparent.color</code></td>
<td>
<p> Color to use when given an NA in z</p>
</td></tr>
<tr valign="top"><td><code>midpoint</code></td>
<td>
<p> If TRUE color scale is formed for midpoints of z
obtained by averaging 4 corners.</p>
</td></tr>
<tr valign="top"><td><code>breaks</code></td>
<td>
<p>Numerical divisions for the color scale. If the default (NA)
is N+1 equally spaced points in the range <code>zlim</code> where N is the number of
colors in <code>col</code>. This is the argument has the same effect as used in the
<code>image</code> and <code>image.plot</code> functions.</p>
</td></tr>
<tr valign="top"><td><code>eps</code></td>
<td>
<p>Amount to inflate the range (1+/- eps) to inlude points on
break endpoints.</p>
</td></tr>
<tr valign="top"><td><code>...</code></td>
<td>
<p> Other arguments that will be passed to the
persp function. The most common is zlim the z limits for the
3-d plot and also the limits to set up the color scale. The
default for zlim is the range of z.</p>
</td></tr>
</table>
<h3>Details</h3>
<p>The legend strip may obscure part of the plot. If so, add this as
another step using image.plot.
</p>
<p>When using <code>drape.color</code> just drop the results into the
<code>col</code> argument of <code>persp</code>. Given this function there are no
surprises how the higher level <code>drape.plot</code> works: it calls
<code>drape.color</code> followed by <code>persp</code> and finally the legend
strip is added with <code>image.plot</code>.
</p>
<p>The color scales essentially default to the ranges of the z
values. However, by specifying zlim and/or zlim2 one has more control
of how the perspective plot is scaled and the limits of the color
scale used to fill the facets. The color assignments are done by
dividing up the zlim2 interval into equally spaced bins and adding a
very small inflation to these limits. The mean z2 values, comprising
an (M-1)X(N-1) matrix, for each facet are discretized to the bins. The
bin numbers then become the indices used for the color scale. If zlim2
is not specified it is the range of the z2 matrix is used to generate
the ranges of the color bar. Note that this may be different than the
range of the mean facets. If z2 is not passed then z is used in its
place and in this case the zlim2 or zlim argument can used to define
the color scale.
</p>
<p>This kind of plot is also supported through the wireframe function in the
<code>lattice</code> package. The advantage of the fields version is that it uses the
standard R graphics functions – and is written in R code.
</p>
<p>The drape plot is also drawn by the fields <code>surface</code> function with
<code>type="P"</code>.
</p>
<h3>Value</h3>
<p><code>drape.plot</code>
If an assignment is made the projection matrix from persp is returned.
This information can be used to add additional 3-d features to the plot.
See the <code>persp</code> help file for an example how to add additional points
and lines using the <code>trans3d</code> function and also the example below.
</p>
<p><code>drape.color</code> If dim( z) = M,N this function returns a list with components:
</p>
<table summary="R valueblock">
<tr valign="top"><td><code>color.index</code></td>
<td>
<p>An (M-1)X(N-1) matrix (midpoint= TRUE) or MXN matrx (midpoint=FALSE) where each element is a text string specifying the color. </p>
</td></tr>
<tr valign="top"><td><code>breaks</code></td>
<td>
<p>The breaks used to assign the numerical values in z to color categories.</p>
</td></tr>
</table>
<h3>Author(s)</h3>
<p>D. Nychka </p>
<h3>See Also</h3>
<p> image.plot, quilt.plot, persp, plot.surface, surface, lattice, trans3d</p>
<h3>Examples</h3>
<pre>
# an obvious choice:
# Dr. R's favorite New Zealand Volcano!
data( volcano)
M<- nrow( volcano)
N<- ncol( volcano)
x<- seq( 0,1,,M)
y<- seq( 0,1,,N)
pm<- drape.plot( x,y,volcano, col=terrain.colors(128))
# use different range for color scale and persp plot
# setting of border omits the mesh lines
drape.plot( x,y,volcano, col=terrain.colors(128),zlim=c(0,300),
zlim2=c( 120,165), border=NA)
# note tranparent color for facets outside the zlim2 range
#The projection has been saved in pm
# add a point marking the summit
max( volcano)-> zsummit
ix<- row( volcano)[volcano==zsummit]
iy<- col( volcano)[volcano==zsummit]
trans3d( x[ix], y[iy],zsummit,pm)-> uv
points( uv, col="magenta", pch="+", cex=2)
# overlay volcano wireframe with gradient in x direction.
dz<- (
volcano[1:(M-1), 1:(N-1)] - volcano[2:(M), 1:(N-1)] +
volcano[1:(M-1), 2:(N)] - volcano[2:(M), 2:(N)]
)/2
# convert dz to a color scale:
zlim<- range( c( dz), na.rm=TRUE)
zcol<-drape.color( dz, zlim =zlim, col = tim.colors(64) )$color.index
# wireframe with these colors
persp( volcano, col=zcol, theta=30, phi=20)
# add legend using image.plot function
image.plot( zlim=zlim, legend.only =TRUE, horizontal =TRUE, col= tim.colors(64))
</pre>
<hr /><div style="text-align: center;">[Package <em>fields</em> version 9.9 <a href="00Index.html">Index</a>]</div>
</body></html>