grid.locator.html 3.1 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>R: Capture a Mouse Click</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.locator {grid}"><tr><td>grid.locator {grid}</td><td align="right">R Documentation</td></tr></table>
<h2>Capture a Mouse Click</h2>


<h3>Description</h3>

<p>
Allows the user to click the mouse once within the current
graphics
device and returns the location of the mouse click within the
current viewport, in the specified coordinate system.
</p>


<h3>Usage</h3>

<pre>
grid.locator(unit = "native")
</pre>


<h3>Arguments</h3>

<table summary="R argblock">
<tr valign="top"><td><code>unit</code></td>
<td>
The coordinate system in which to return the location
of the mouse click.
See the <code><a href="unit.html">unit</a></code> function for valid coordinate systems.</td></tr>
</table>

<h3>Details</h3>

<p>
This function is modal (like the graphics package
function <code>locator</code>) so
the command line and graphics drawing is blocked until
the use has clicked the mouse  in the current device.
</p>


<h3>Value</h3>

<p>
A unit object representing the location of the mouse click within the
current viewport, in the specified coordinate system.
<br>
If the user did not click mouse button 1, the function
(invisibly) returns <code>NULL</code>.</p>

<h3>Author(s)</h3>

<p>
Paul Murrell
</p>


<h3>See Also</h3>

<p>
<code><a href="viewport.html">viewport</a></code>, <code><a href="unit.html">unit</a></code>,
<code>locator</code> in package <STRONG>graphics</STRONG>, and for an application
see <code><a href="../../lattice/html/interaction.html">trellis.focus</a></code> and
<code><a href="../../lattice/html/interaction.html">panel.identify</a></code> in package <STRONG>lattice</STRONG>.
</p>


<h3>Examples</h3>

<pre>
if (interactive()) {
  ## Need to write a more sophisticated unit as.character method
  unittrim &lt;- function(unit) {
    sub("^([0-9]+|[0-9]+[.][0-9])[0-9]*", "\\1", as.character(unit))
  }
  do.click &lt;- function(unit) {
    click.locn &lt;- grid.locator(unit)
    grid.segments(unit.c(click.locn$x, unit(0, "npc")),
                  unit.c(unit(0, "npc"), click.locn$y),
                  click.locn$x, click.locn$y,
                  gp=gpar(lty="dashed", col="grey"))
    grid.points(click.locn$x, click.locn$y, pch=16, size=unit(1, "mm"))
    clickx &lt;- unittrim(click.locn$x)
    clicky &lt;- unittrim(click.locn$y)
    grid.text(paste("(", clickx, ", ", clicky, ")", sep=""),
              click.locn$x + unit(2, "mm"), click.locn$y,
              just="left")
  }
  do.click("inches")
  pushViewport(viewport(width=0.5, height=0.5,
                         xscale=c(0, 100), yscale=c(0, 10)))
  grid.rect()
  grid.xaxis()
  grid.yaxis()
  do.click("native")
  popViewport()  
}
</pre>



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

</body></html>