grid.xspline.html
7.32 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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>R: Draw an Xspline</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 grid.xspline {grid}"><tr><td>grid.xspline {grid}</td><td align="right">R Documentation</td></tr></table>
<h2>Draw an Xspline</h2>
<h3>Description</h3>
<p>
These functions create and draw an xspline, a curve drawn
relative to control points.
</p>
<h3>Usage</h3>
<pre>
grid.xspline(...)
xsplineGrob(x = c(0, 0.5, 1, 0.5), y = c(0.5, 1, 0.5, 0),
id = NULL, id.lengths = NULL,
default.units = "npc",
shape = 0, open = TRUE, arrow = NULL, repEnds = TRUE,
name = NULL, gp = gpar(), vp = NULL)
</pre>
<h3>Arguments</h3>
<table summary="R argblock">
<tr valign="top"><td><code>x</code></td>
<td>
A numeric vector or unit object specifying x-locations of
spline control points.</td></tr>
<tr valign="top"><td><code>y</code></td>
<td>
A numeric vector or unit object specifying y-locations of
spline control points.</td></tr>
<tr valign="top"><td><code>id</code></td>
<td>
A numeric vector used to separate locations in <code>x</code> and
<code>y</code> into multiple xsplines. All locations with the same
<code>id</code> belong to the same xspline.</td></tr>
<tr valign="top"><td><code>id.lengths</code></td>
<td>
A numeric vector used to separate locations in <code>x</code> and
<code>y</code> into multiple xspline. Specifies consecutive blocks of
locations which make up separate xsplines.</td></tr>
<tr valign="top"><td><code>default.units</code></td>
<td>
A string indicating the default units to use
if <code>x</code> or <code>y</code>
are only given as numeric vectors.</td></tr>
<tr valign="top"><td><code>shape</code></td>
<td>
A numeric vector of values between -1 and 1, which
control the shape of the spline relative to the control points.</td></tr>
<tr valign="top"><td><code>open</code></td>
<td>
A logical value indicating whether the spline is
a line or a closed shape.</td></tr>
<tr valign="top"><td><code>arrow</code></td>
<td>
A list describing arrow heads to place at either end
of the xspline, as produced by the <code>arrow</code> function.</td></tr>
<tr valign="top"><td><code>repEnds</code></td>
<td>
A logical value indicating whether the first and
last control points should be replicated for drawing the curve
(see Details below).</td></tr>
<tr valign="top"><td><code>name</code></td>
<td>
A character identifier. </td></tr>
<tr valign="top"><td><code>gp</code></td>
<td>
An object of class <code>gpar</code>, typically the output
from a call to the function <code>gpar</code>. This is basically
a list of graphical parameter settings.</td></tr>
<tr valign="top"><td><code>vp</code></td>
<td>
A Grid viewport object (or NULL).</td></tr>
<tr valign="top"><td><code>...</code></td>
<td>
Arguments to be passed to <code>xsplineGrob</code>.</td></tr>
</table>
<h3>Details</h3>
<p>
Both functions create an xspline grob (a graphical object describing an
xspline), but only <code>grid.xspline</code>
draws the xspline.
</p>
<p>
An xspline is a line drawn relative to control points. For each
control point, the line
may pass through (interpolate) the control point or it
may only approach (approximate) the control
point; the behaviour is determined by a shape parameter for each
control point.
</p>
<p>
If the shape parameter is greater than zero, the spline
approximates the control points (and is
very similar to a cubic B-spline when the shape is
1). If the shape parameter is less than zero, the spline interpolates
the control points (and is very similar to a Catmull-Rom spline when
the shape is -1). If the shape parameter is 0, the spline forms a
sharp corner at that control point.
</p>
<p>
For open xsplines, the start and end control points must have a shape
of 0 (and non-zero values are silently converted to zero without warning).
</p>
<p>
For open xsplines, by default the start and end control points are
actually replicated before the curve is drawn. A curve is drawn
between (interpolating or approximating)
the second and third of each set of four control points, so
this default behaviour ensures that
the resulting curve starts at the first control point you have
specified and ends at the last control point.
The default
behaviour can be turned off via the <code>repEnds</code> argument,
in which case the curve that is drawn starts (approximately) at
the second control point and ends (approximately) at the first and
second-to-last control point.
</p>
<p>
The <code>repEnds</code> argument is ignored for closed xsplines.
</p>
<p>
Missing values are not allowed for <code>x</code> and <code>y</code>
(i.e., it is not valid for a control point to be missing).
</p>
<p>
For closed xsplines, a curve is automatically drawn
between the final control point and the initial control point.
</p>
<h3>Value</h3>
<p>
A grob object.</p>
<h3>References</h3>
<p>
Blanc, C. and Schlick, C. (1995),
"X-splines : A Spline Model Designed for the End User",
in <EM>Proceedings of SIGGRAPH 95</EM>.
</p>
<h3>See Also</h3>
<p>
<a href="Grid.html">Grid</a>,
<code><a href="viewport.html">viewport</a></code>,
<code><a href="arrow.html">arrow</a></code>
</p>
<h3>Examples</h3>
<pre>
x <- c(0.25, 0.25, 0.75, 0.75)
y <- c(0.25, 0.75, 0.75, 0.25)
xsplineTest <- function(s, i, j, open) {
pushViewport(viewport(layout.pos.col=j, layout.pos.row=i))
grid.points(x, y, default.units="npc", pch=16, size=unit(2, "mm"))
grid.xspline(x, y, shape=s, open=open, gp=gpar(fill="grey"))
grid.text(s, gp=gpar(col="grey"),
x=unit(x, "npc") + unit(c(-1, -1, 1, 1), "mm"),
y=unit(y, "npc") + unit(c(-1, 1, 1, -1), "mm"),
hjust=c(1, 1, 0, 0),
vjust=c(1, 0, 0, 1))
popViewport()
}
pushViewport(viewport(width=.5, x=0, just="left",
layout=grid.layout(3, 3, respect=TRUE)))
pushViewport(viewport(layout.pos.row=1))
grid.text("Open Splines", y=1, just="bottom")
popViewport()
xsplineTest(c(0, -1, -1, 0), 1, 1, TRUE)
xsplineTest(c(0, -1, 0, 0), 1, 2, TRUE)
xsplineTest(c(0, -1, 1, 0), 1, 3, TRUE)
xsplineTest(c(0, 0, -1, 0), 2, 1, TRUE)
xsplineTest(c(0, 0, 0, 0), 2, 2, TRUE)
xsplineTest(c(0, 0, 1, 0), 2, 3, TRUE)
xsplineTest(c(0, 1, -1, 0), 3, 1, TRUE)
xsplineTest(c(0, 1, 0, 0), 3, 2, TRUE)
xsplineTest(c(0, 1, 1, 0), 3, 3, TRUE)
popViewport()
pushViewport(viewport(width=.5, x=1, just="right",
layout=grid.layout(3, 3, respect=TRUE)))
pushViewport(viewport(layout.pos.row=1))
grid.text("Closed Splines", y=1, just="bottom")
popViewport()
xsplineTest(c(-1, -1, -1, -1), 1, 1, FALSE)
xsplineTest(c(-1, -1, 0, -1), 1, 2, FALSE)
xsplineTest(c(-1, -1, 1, -1), 1, 3, FALSE)
xsplineTest(c( 0, 0, -1, 0), 2, 1, FALSE)
xsplineTest(c( 0, 0, 0, 0), 2, 2, FALSE)
xsplineTest(c( 0, 0, 1, 0), 2, 3, FALSE)
xsplineTest(c( 1, 1, -1, 1), 3, 1, FALSE)
xsplineTest(c( 1, 1, 0, 1), 3, 2, FALSE)
xsplineTest(c( 1, 1, 1, 1), 3, 3, FALSE)
popViewport()
</pre>
<hr><div align="center">[Package <em>grid</em> version 2.5.1 <a href="00Index.html">Index]</a></div>
</body></html>