EVOLUTION-MANAGER
Edit File: unit.html
<!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: Function to Create a Unit Object</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 unit {grid}"><tr><td>unit {grid}</td><td style="text-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> <p>A numeric vector.</p> </td></tr> <tr valign="top"><td><code>units</code></td> <td> <p>A character vector specifying the units for the corresponding numeric values.</p> </td></tr> <tr valign="top"><td><code>data</code></td> <td> <p>This argument is used to supply extra information for special <code>unit</code> types.</p> </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: </p> <dl> <dt><code>"npc"</code></dt><dd><p>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.</p> </dd> <dt><code>"cm"</code></dt><dd><p>Centimetres.</p> </dd> <dt><code>"inches"</code></dt><dd><p>Inches. 1 in = 2.54 cm.</p> </dd> <dt><code>"mm"</code></dt><dd><p>Millimetres. 10 mm = 1 cm.</p> </dd> <dt><code>"points"</code></dt><dd><p>Points. 72.27 pt = 1 in.</p> </dd> <dt><code>"picas"</code></dt><dd><p>Picas. 1 pc = 12 pt.</p> </dd> <dt><code>"bigpts"</code></dt><dd><p>Big Points. 72 bp = 1 in.</p> </dd> <dt><code>"dida"</code></dt><dd><p>Dida. 1157 dd = 1238 pt.</p> </dd> <dt><code>"cicero"</code></dt><dd><p>Cicero. 1 cc = 12 dd.</p> </dd> <dt><code>"scaledpts"</code></dt><dd><p>Scaled Points. 65536 sp = 1 pt.</p> </dd> <dt><code>"lines"</code></dt><dd><p>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>).</p> </dd> <dt><code>"char"</code></dt><dd><p>Multiples of nominal font height of the viewport (as specified by the viewport's <code>fontsize</code>).</p> </dd> <dt><code>"native"</code></dt><dd><p>Locations and dimensions are relative to the viewport's <code>xscale</code> and <code>yscale</code>.</p> </dd> <dt><code>"snpc"</code></dt><dd><p>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).</p> </dd> <dt><code>"strwidth"</code></dt><dd><p>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.</p> </dd> <dt><code>"strheight"</code></dt><dd><p>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.</p> </dd> <dt><code>"grobwidth"</code></dt><dd><p>Multiples of the width of the grob specified in the <code>data</code> argument.</p> </dd> <dt><code>"grobheight"</code></dt><dd><p>Multiples of the height of the grob specified in the <code>data</code> argument.</p> </dd> </dl> <p>A number of variations are also allowed for the most common units. For example, it is possible to use <code>"in"</code> or <code>"inch"</code> instead of <code>"inches"</code> and <code>"centimetre"</code> or <code>"centimeter"</code> instead of <code>"cm"</code>. </p> <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, </p> <pre> unit(rep(1, 3), c("npc", "strwidth", "inches"), data = list(NULL, "my string", NULL)) </pre><p>. </p> <p>It is possible to subset unit objects in the normal way and to perform subassignment (see the examples), 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> <p>There is a <code>format</code> method for units, which should respond to the arguments for the default <code>format</code> method, e.g., <code>digits</code> to control the number of significant digits printed for numeric values. </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")) x <- unit(1:5, "npc") x[2:4] x[2:4] <- unit(1, "mm") x </pre> <hr /><div style="text-align: center;">[Package <em>grid</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>