grid.convert.html
5.96 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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>R: Convert Between Different grid Coordinate Systems</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.convert {grid}"><tr><td>grid.convert {grid}</td><td align="right">R Documentation</td></tr></table>
<h2>Convert Between Different grid Coordinate Systems</h2>
<h3>Description</h3>
<p>
These functions take a unit object and convert it to an
equivalent
unit object in a different coordinate system.
</p>
<h3>Usage</h3>
<pre>
convertX(x, unitTo, valueOnly = FALSE)
convertY(x, unitTo, valueOnly = FALSE)
convertWidth(x, unitTo, valueOnly = FALSE)
convertHeight(x, unitTo, valueOnly = FALSE)
convertUnit(x, unitTo,
axisFrom = "x", typeFrom = "location",
axisTo = axisFrom, typeTo = typeFrom,
valueOnly = FALSE)
grid.convertX(x, unitTo, valueOnly = FALSE)
grid.convertY(x, unitTo, valueOnly = FALSE)
grid.convertWidth(x, unitTo, valueOnly = FALSE)
grid.convertHeight(x, unitTo, valueOnly = FALSE)
grid.convert(x, unitTo,
axisFrom = "x", typeFrom = "location",
axisTo = axisFrom, typeTo = typeFrom,
valueOnly = FALSE)
</pre>
<h3>Arguments</h3>
<table summary="R argblock">
<tr valign="top"><td><code>x</code></td>
<td>
A unit object. </td></tr>
<tr valign="top"><td><code>unitTo</code></td>
<td>
The coordinate system to convert the unit to.
See the <code><a href="unit.html">unit</a></code> function for valid coordinate systems.</td></tr>
<tr valign="top"><td><code>axisFrom</code></td>
<td>
Either <code>"x"</code> or <code>"y"</code> to indicate
whether the unit object represents a value in the x- or
y-direction. </td></tr>
<tr valign="top"><td><code>typeFrom</code></td>
<td>
Either <code>"location"</code> or <code>"dimension"</code>
to indicate whether the unit object represents a location or a
length. </td></tr>
<tr valign="top"><td><code>axisTo</code></td>
<td>
Same as <code>axisFrom</code>, but applies to the unit object
that is to be created. </td></tr>
<tr valign="top"><td><code>typeTo</code></td>
<td>
Same as <code>typeFrom</code>, but applies to the unit object
that is to be created. </td></tr>
<tr valign="top"><td><code>valueOnly</code></td>
<td>
A logical indicating. If <code>TRUE</code> then
the function does not return a unit object, but rather only the
converted numeric values. </td></tr>
</table>
<h3>Details</h3>
<p>
The <code>convertUnit</code> function allows for general-purpose
conversions. The other four functions are just more convenient
front-ends to it for the most common conversions.
</p>
<p>
The conversions occur within the current viewport.
</p>
<p>
It is not currently possible to convert to all valid coordinate systems
(e.g., "strwidth" or "grobwidth"). I'm not sure if all of these
are impossible, they just seem implausible at this stage.
</p>
<p>
In normal usage of grid, these functions should not be necessary.
If you want to express a location or dimension in inches rather
than user coordinates then you should simply do something like
<code>unit(1, "inches")</code> rather than something like
<code>unit(0.134, "native")</code>.
</p>
<p>
In some cases, however, it is necessary for the user to
perform calculations on a unit value and this function becomes
necessary. In such cases, please take note of the warning below.
</p>
<p>
The grid.* versions are just previous incarnations which have
been deprecated.
</p>
<h3>Value</h3>
<p>
A unit object in the specified coordinate system
(unless <code>valueOnly</code> is <code>TRUE</code> in which case
the returned value is a numeric).</p>
<h3>Warning</h3>
<p>
The conversion is only valid for the current device size.
If the device is resized then at least some conversions will
become invalid. For example, suppose that I create a unit
object as follows: <code>oneinch <- convertUnit(unit(1, "inches"),
"native"</code>. Now if I resize the device, the unit object in
oneinch no longer corresponds to a physical length of 1 inch.
</p>
<h3>Author(s)</h3>
<p>
Paul Murrell
</p>
<h3>See Also</h3>
<p>
<code><a href="unit.html">unit</a></code>
</p>
<h3>Examples</h3>
<pre>
## A tautology
convertX(unit(1, "inches"), "inches")
## The physical units
convertX(unit(2.54, "cm"), "inches")
convertX(unit(25.4, "mm"), "inches")
convertX(unit(72.27, "points"), "inches")
convertX(unit(1/12*72.27, "picas"), "inches")
convertX(unit(72, "bigpts"), "inches")
convertX(unit(1157/1238*72.27, "dida"), "inches")
convertX(unit(1/12*1157/1238*72.27, "cicero"), "inches")
convertX(unit(65536*72.27, "scaledpts"), "inches")
convertX(unit(1/2.54, "inches"), "cm")
convertX(unit(1/25.4, "inches"), "mm")
convertX(unit(1/72.27, "inches"), "points")
convertX(unit(1/(1/12*72.27), "inches"), "picas")
convertX(unit(1/72, "inches"), "bigpts")
convertX(unit(1/(1157/1238*72.27), "inches"), "dida")
convertX(unit(1/(1/12*1157/1238*72.27), "inches"), "cicero")
convertX(unit(1/(65536*72.27), "inches"), "scaledpts")
pushViewport(viewport(width=unit(1, "inches"),
height=unit(2, "inches"),
xscale=c(0, 1),
yscale=c(1, 3)))
## Location versus dimension
convertY(unit(2, "native"), "inches")
convertHeight(unit(2, "native"), "inches")
## From "x" to "y" (the conversion is via "inches")
convertUnit(unit(1, "native"), "native",
axisFrom="x", axisTo="y")
## Convert several values at once
convertX(unit(c(0.5, 2.54), c("npc", "cm")),
c("inches", "native"))
popViewport()
## Convert a complex unit
convertX(unit(1, "strwidth", "Hello"), "native")
</pre>
<hr><div align="center">[Package <em>grid</em> version 2.5.1 <a href="00Index.html">Index]</a></div>
</body></html>