EVOLUTION-MANAGER
Edit File: grid.locator.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Capture a Mouse Click</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <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 style="text-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> <p> 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.</p> </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. </p> <p>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><a href="../../graphics/html/locator.html">locator</a></code> in package <span class="pkg">graphics</span>, 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 <a href="https://CRAN.R-project.org/package=lattice"><span class="pkg">lattice</span></a>. </p> <h3>Examples</h3> <pre> if (dev.interactive()) { ## Need to write a more sophisticated unit as.character method unittrim <- function(unit) { sub("^([0-9]+|[0-9]+[.][0-9])[0-9]*", "\\1", as.character(unit)) } do.click <- function(unit) { click.locn <- 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 <- unittrim(click.locn$x) clicky <- unittrim(click.locn$y) grid.text(paste0("(", clickx, ", ", clicky, ")"), click.locn$x + unit(2, "mm"), click.locn$y, just="left") } grid.newpage() # (empty slate) ## device do.click("inches") Sys.sleep(1) 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 style="text-align: center;">[Package <em>grid</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>