grid.text                package:grid                R Documentation

_D_r_a_w _T_e_x_t _i_n _a _G_r_i_d _V_i_e_w_p_o_r_t

_D_e_s_c_r_i_p_t_i_o_n:

     This function draws a piece of text.

_U_s_a_g_e:

     grid.text(label, x = unit(0.5, "npc"), y = unit(0.5, "npc"), 
               just = "centre", rot = 0,
               check.overlap = FALSE, default.units = "npc",
               gp=gpar(), draw = TRUE, vp = NULL)

_A_r_g_u_m_e_n_t_s:

   label: A vector of strings or expressions to draw.

       x: A numeric vector or unit object specifying x-values.

       y: A numeric vector or unit object specifying y-values.

    just: The justification of the text about its (x, y) location.  If
          two values are given, the first specifies horizontal
          justification and the second specifies vertical
          justification.

     rot: The angle to rotate the text.

check.overlap: A logical value to indicate whether to check for and
          omit overlapping text.

default.units: A string indicating the default units to use if 'x' or
          'y' are only given as numeric vectors.

      gp: An object of class 'gpar', typically the output from a call
          to the function 'gpar'.  This is basically a list of
          graphical parameter settings.

    draw: A logical value indicating whether graphics output should be
          produced.

      vp: A Grid viewport object (or NULL).

_D_e_t_a_i_l_s:

     If the 'label' argument is an expression, the output is formatted
     as a mathematical annotation, as for base graphics text.

     The '"grob"' object contains an object of class '"text"'.

_V_a_l_u_e:

     An object of class '"grob"'.

_A_u_t_h_o_r(_s):

     Paul Murrell

_S_e_e _A_l_s_o:

     Grid, 'viewport'

_E_x_a_m_p_l_e_s:

     # Clipping of overlapping text
     grid.newpage()
     x <- runif(20)
     y <- runif(20)
     rot <- runif(20, 0, 360)
     grid.text("SOMETHING NICE AND BIG", x=x, y=y, rot=rot,
               gp=gpar(fontsize=20, col="grey"))
     grid.text("SOMETHING NICE AND BIG", x=x, y=y, rot=rot,
               gp=gpar(fontsize=20), check=TRUE)
     # Specifying the justification of text
     grid.newpage()
     draw.text <- function(just, i, j) {
       grid.text("ABCD", x=x[j], y=y[i], just=just)
       grid.text(deparse(substitute(just)), x=x[j], y=y[i] + unit(2, "lines"),
                 gp=gpar(col="grey", fontsize=8))
     }
     x <- unit(1:4/5, "npc")
     y <- unit(1:4/5, "npc")
     grid.grill(h=y, v=x, gp=gpar(col="grey"))
     draw.text(c("bottom"), 1, 1)
     draw.text(c("left", "bottom"), 2, 1)
     draw.text(c("right", "bottom"), 3, 1)
     draw.text(c("centre", "bottom"), 4, 1)
     draw.text(c("centre"), 1, 2)
     draw.text(c("left", "centre"), 2, 2)
     draw.text(c("right", "centre"), 3, 2)
     draw.text(c("centre", "centre"), 4, 2)
     draw.text(c("top"), 1, 3)
     draw.text(c("left", "top"), 2, 3)
     draw.text(c("right", "top"), 3, 3)
     draw.text(c("centre", "top"), 4, 3)
     draw.text(c(), 1, 4)
     draw.text(c("left"), 2, 4)
     draw.text(c("right"), 3, 4)
     draw.text(c("centre"), 4, 4)
     # A simple mathematical annotation example
     grid.newpage()
     grid.text(expression(z[i] == sqrt(x[i]^2 + y[i]^2)),
       gp=gpar(cex=2))

