unit                  package:grid                  R Documentation

_F_u_n_c_t_i_o_n _t_o _C_r_e_a_t_e _a _U_n_i_t _O_b_j_e_c_t

_D_e_s_c_r_i_p_t_i_o_n:

     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.

_U_s_a_g_e:

     unit(x, units, data=NULL)

_A_r_g_u_m_e_n_t_s:

       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.

_D_e_t_a_i_l_s:

     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:

     '"_n_p_c"' 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.

     '"_c_m"' Centimetres.

     '"_i_n_c_h_e_s"' Inches.  1 in = 2.54 cm.

     '"_m_m"' Millimetres.  10 mm = 1 cm.

     '"_p_o_i_n_t_s"' Points.  72.27 pt = 1 in.

     '"_p_i_c_a_s"' Picas.  1 pc = 12 pt.

     '"_b_i_g_p_t_s"' Big Points.  72 bp = 1 in.

     '"_d_i_d_a"' Dida. 1157 dd = 1238 pt.

     '"_c_i_c_e_r_o"' Cicero.  1 cc = 12 dd.

     '"_s_c_a_l_e_d_p_t_s"' Scaled Points.  65536 sp = 1 pt.

     '"_l_i_n_e_s"' 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 'fontsize' and 'lineheight').

     '"_c_h_a_r"' Multiples of nominal font height of the viewport (as
          specified by the viewport's 'fontsize').

     '"_n_a_t_i_v_e"' Locations and dimensions are relative to the viewport's
          'xscale' and 'yscale'.

     '"_s_n_p_c"' Square Normalised Parent Coordinates. Same as Normalised
          Parent Coordinates, except gives the same answer for
          horizontal and vertical locations/dimensions.  It uses the
          _lesser_ 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).

     '"_s_t_r_w_i_d_t_h"' Multiples of the width of the string specified in the
          'data' argument.  The font size is determined by the
          pointsize of the viewport.

     '"_s_t_r_h_e_i_g_h_t"' Multiples of the height of the string specified in
          the 'data' argument.  The font size is determined by the
          pointsize of the viewport.

     '"_g_r_o_b_w_i_d_t_h"' Multiples of the width of the grob specified in the
          'data' argument.

     '"_g_r_o_b_h_e_i_g_h_t"' Multiples of the height of the grob specified in
          the 'data' argument.

     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"))').

_V_a_l_u_e:

     An object of class '"unit"'.

_W_A_R_N_I_N_G:

     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"'.

_A_u_t_h_o_r(_s):

     Paul Murrell

_S_e_e _A_l_s_o:

     'unit.c' and 'unit.length'

_E_x_a_m_p_l_e_s:

     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"))

