grid.locator.html
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!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 <- 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(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>