unit {grid} | R Documentation |
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.
unit(x, units, data=NULL)
x |
A numeric vector. |
units |
A character vector specifying the units for the corresponding numeric values. |
data |
This argument is used to supply extra information
for special unit types. |
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 units
specifies
what coordinate system to use within that viewport.
Possible units
(coordinate systems) are:
"npc"
"cm"
"inches"
"mm"
"points"
"picas"
"bigpts"
"dida"
"cicero"
"scaledpts"
"lines"
fontsize
and lineheight
)."char"
fontsize
)."native"
xscale
and yscale
."snpc"
"strwidth"
data
argument. The font size is
determined by the pointsize of the viewport."strheight"
data
argument. The font size is
determined by the pointsize of the viewport."grobwidth"
data
argument."grobheight"
data
argument.
A special units
value of "null"
is also allowed,
but only makes sense when used in specifying widths of columns
or heights of rows in grid layouts (see grid.layout
).
The data
argument must be a list when the unit.length()
is greater than 1. For example,
unit(rep(1, 3), c("npc", "strwidth", "inches"),
data=list(NULL, "my string", NULL))
.
It is possible to subset unit objects in the normal way
(e.g., unit(1:5, "npc")[2:4]
), but a special function
unit.c
is provided for combining unit objects.
Certain arithmetic and summary operations are defined for
unit objects. In particular, it is possible to add and subtract
unit objects (e.g., unit(1, "npc") - unit(1, "inches")
),
and to specify the minimum or maximum of a list
of unit objects (e.g., min(unit(0.5, "npc"), unit(1,
"inches"))
).
An object of class "unit"
.
A special function unit.length
is provided for
determining the number of unit values in a unit object.
The length
function will work in some cases, but in general
will not give the right answer.
There is also a special function unit.c
for concatenating
several unit objects.
The c
function will not give the right answer.
There used to be "mylines"
, "mychar"
, "mystrwidth"
,
"mystrheight"
units. These will still be accepted, but
work exactly the same as
"lines"
, "char"
, "strwidth"
,
"strheight"
.
Paul Murrell
unit.c
and
unit.length
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"))