unit.html
5.81 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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>R: Function to Create a Unit Object</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 unit {grid}"><tr><td>unit {grid}</td><td align="right">R Documentation</td></tr></table>
<h2>Function to Create a Unit Object</h2>
<h3>Description</h3>
<p>
This function creates a unit object — a vector of unit values.
A unit value is typically just a single numeric value with an
associated unit.
</p>
<h3>Usage</h3>
<pre>
unit(x, units, data=NULL)
</pre>
<h3>Arguments</h3>
<table summary="R argblock">
<tr valign="top"><td><code>x</code></td>
<td>
A numeric vector.</td></tr>
<tr valign="top"><td><code>units</code></td>
<td>
A character vector specifying the units for the
corresponding numeric values.</td></tr>
<tr valign="top"><td><code>data</code></td>
<td>
This argument is used to supply extra information
for special <code>unit</code> types.</td></tr>
</table>
<h3>Details</h3>
<p>
Unit objects allow the user to specify locations and dimensions
in a large number of different coordinate systems. All drawing
occurs relative to a viewport and the <code>units</code> specifies
what coordinate system to use within that viewport.
</p>
<p>
Possible <code>units</code> (coordinate systems) are:
<dl>
<dt><code>"npc"</code></dt><dd>Normalised Parent Coordinates (the default).
The origin of the viewport is (0, 0) and the viewport has a width
and height of 1 unit. For example, (0.5, 0.5) is the centre of
the viewport.</dd>
<dt><code>"cm"</code></dt><dd>Centimetres.</dd>
<dt><code>"inches"</code></dt><dd>Inches. 1 in = 2.54 cm.</dd>
<dt><code>"mm"</code></dt><dd>Millimetres. 10 mm = 1 cm.</dd>
<dt><code>"points"</code></dt><dd>Points. 72.27 pt = 1 in.</dd>
<dt><code>"picas"</code></dt><dd>Picas. 1 pc = 12 pt.</dd>
<dt><code>"bigpts"</code></dt><dd>Big Points. 72 bp = 1 in.</dd>
<dt><code>"dida"</code></dt><dd>Dida. 1157 dd = 1238 pt.</dd>
<dt><code>"cicero"</code></dt><dd>Cicero. 1 cc = 12 dd.</dd>
<dt><code>"scaledpts"</code></dt><dd>Scaled Points. 65536 sp = 1 pt.</dd>
<dt><code>"lines"</code></dt><dd>Lines of text. Locations and dimensions
are in terms of multiples of the default text size of the viewport
(as specified by the viewport's <code>fontsize</code> and <code>lineheight</code>).</dd>
<dt><code>"char"</code></dt><dd>Multiples of nominal font height of the
viewport (as specified by the viewport's <code>fontsize</code>).</dd>
<dt><code>"native"</code></dt><dd>Locations and dimensions are relative to
the viewport's <code>xscale</code> and <code>yscale</code>.</dd>
<dt><code>"snpc"</code></dt><dd>Square Normalised Parent Coordinates.
Same as Normalised Parent Coordinates, except gives the same answer for
horizontal and vertical locations/dimensions. It uses the
<EM>lesser</EM> of npc-width and npc-height. This is useful for making
things which are a proportion of the viewport, but have to be square
(or have a fixed aspect ratio).</dd>
<dt><code>"strwidth"</code></dt><dd>Multiples of the width of the string
specified in the <code>data</code> argument. The font size is
determined by the pointsize of the viewport.</dd>
<dt><code>"strheight"</code></dt><dd>Multiples of the height of the string
specified in the <code>data</code> argument. The font size is
determined by the pointsize of the viewport.</dd>
<dt><code>"grobwidth"</code></dt><dd>Multiples of the width of the grob
specified in the <code>data</code> argument.</dd>
<dt><code>"grobheight"</code></dt><dd>Multiples of the height of the grob
specified in the <code>data</code> argument.</dd>
</dl>
<p>
A special <code>units</code> value of <code>"null"</code> is also allowed,
but only makes sense when used in specifying widths of columns
or heights of rows in grid layouts (see <code><a href="grid.layout.html">grid.layout</a></code>).
</p>
<p>
The <code>data</code> argument must be a list when the <code>unit.length()</code>
is greater than 1. For example,
<code>unit(rep(1, 3), c("npc", "strwidth", "inches"),
data=list(NULL, "my string", NULL))</code>.
</p>
<p>
It is possible to subset unit objects in the normal way
(e.g., <code>unit(1:5, "npc")[2:4]</code>), but a special function
<code>unit.c</code> is provided for combining unit objects.
</p>
<p>
Certain arithmetic and summary operations are defined for
unit objects. In particular, it is possible to add and subtract
unit objects (e.g., <code>unit(1, "npc") - unit(1, "inches")</code>),
and to specify the minimum or maximum of a list
of unit objects (e.g., <code>min(unit(0.5, "npc"), unit(1,
"inches"))</code>).
</p>
<h3>Value</h3>
<p>
An object of class <code>"unit"</code>.</p>
<h3>WARNING</h3>
<p>
There is a special function <code>unit.c</code> for concatenating
several unit objects.
</p>
<p>
The <code>c</code> function will not give the right answer.
</p>
<p>
There used to be <code>"mylines"</code>, <code>"mychar"</code>, <code>"mystrwidth"</code>,
<code>"mystrheight"</code> units. These will still be accepted, but
work exactly the same as
<code>"lines"</code>, <code>"char"</code>, <code>"strwidth"</code>,
<code>"strheight"</code>.
</p>
<h3>Author(s)</h3>
<p>
Paul Murrell
</p>
<h3>See Also</h3>
<p>
<code><a href="unit.c.html">unit.c</a></code>
</p>
<h3>Examples</h3>
<pre>
unit(1, "npc")
unit(1:3/4, "npc")
unit(1:3/4, "npc") + unit(1, "inches")
min(unit(0.5, "npc"), unit(1, "inches"))
unit.c(unit(0.5, "npc"), unit(2, "inches") + unit(1:3/4, "npc"),
unit(1, "strwidth", "hi there"))
</pre>
<hr><div align="center">[Package <em>grid</em> version 2.5.1 <a href="00Index.html">Index]</a></div>
</body></html>