grid.text.html 5.29 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>R: Draw Text</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.text {grid}"><tr><td>grid.text {grid}</td><td align="right">R Documentation</td></tr></table>
<h2>Draw Text</h2>


<h3>Description</h3>

<p>
These functions create and draw text and <a href="../../grDevices/html/plotmath.html">plotmath</a> expressions.
</p>


<h3>Usage</h3>

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

textGrob(label, x = unit(0.5, "npc"), y = unit(0.5, "npc"), 
          just = "centre", hjust = NULL, vjust = NULL, rot = 0,
          check.overlap = FALSE, default.units = "npc",
          name = NULL, gp = gpar(), vp = NULL)
</pre>


<h3>Arguments</h3>

<table summary="R argblock">
<tr valign="top"><td><code>label</code></td>
<td>
A character or <a href="../../base/html/expression.html">expression</a> vector.  Other
objects are coerced by <code><a href="../../grDevices/html/as.graphicsAnnot.html">as.graphicsAnnot</a></code>.</td></tr>
<tr valign="top"><td><code>x</code></td>
<td>
A numeric vector or unit object specifying x-values.</td></tr>
<tr valign="top"><td><code>y</code></td>
<td>
A numeric vector or unit object specifying y-values.</td></tr>
<tr valign="top"><td><code>just</code></td>
<td>
The justification of the text 
relative to its (x, y) location.  If there are two values, the first
value specifies horizontal justification and the second value specifies
vertical justification.  Possible string values are: <code>"left"</code>,
<code>"right"</code>, <code>"centre"</code>, <code>"center"</code>, <code>"bottom"</code>,
and <code>"top"</code>.  For numeric values, 0 means left alignment
and 1 means right alignment.
</td></tr>
<tr valign="top"><td><code>hjust</code></td>
<td>
A numeric vector specifying horizontal justification.
If specified, overrides the <code>just</code> setting.</td></tr>
<tr valign="top"><td><code>vjust</code></td>
<td>
A numeric vector specifying vertical justification.
If specified, overrides the <code>just</code> setting.</td></tr>
<tr valign="top"><td><code>rot</code></td>
<td>
The angle to rotate the text.</td></tr>
<tr valign="top"><td><code>check.overlap</code></td>
<td>
A logical value to indicate whether to
check for and omit overlapping text.</td></tr>
<tr valign="top"><td><code>default.units</code></td>
<td>
A string indicating the default units to use
if <code>x</code> or <code>y</code>
are only given as numeric vectors.</td></tr>
<tr valign="top"><td><code>name</code></td>
<td>
A character identifier. </td></tr>
<tr valign="top"><td><code>gp</code></td>
<td>
An object of class <code>gpar</code>, typically the output
from a call to the function <code>gpar</code>.  This is basically
a list of graphical parameter settings.</td></tr>
<tr valign="top"><td><code>draw</code></td>
<td>
A logical value indicating whether graphics output
should be produced.</td></tr>
<tr valign="top"><td><code>vp</code></td>
<td>
A Grid viewport object (or NULL).</td></tr>
</table>

<h3>Details</h3>

<p>
Both functions create a text grob (a graphical object describing
text), but only <code>grid.text</code>
draws the text (and then only if <code>draw</code> is <code>TRUE</code>).
</p>
<p>
If the <code>label</code> argument is an expression, the output is
formatted as a mathematical annotation, as for base graphics text.
</p>


<h3>Value</h3>

<p>
A text grob.  <code>grid.text</code> returns the value invisibly.</p>

<h3>Author(s)</h3>

<p>
Paul Murrell
</p>


<h3>See Also</h3>

<p>
<a href="Grid.html">Grid</a>,
<code><a href="viewport.html">viewport</a></code>
</p>


<h3>Examples</h3>

<pre>
grid.newpage()
x &lt;- stats::runif(20)
y &lt;- stats::runif(20)
rot &lt;- stats::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)
grid.newpage()
draw.text &lt;- 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 &lt;- unit(1:4/5, "npc")
y &lt;- 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)
</pre>



<hr><div align="center">[Package <em>grid</em> version 2.5.1 <a href="00Index.html">Index]</a></div>

</body></html>