grid.locator package:grid R Documentation _C_a_p_t_u_r_e _a _M_o_u_s_e _C_l_i_c_k _D_e_s_c_r_i_p_t_i_o_n: 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. _U_s_a_g_e: grid.locator(unit = "native") _A_r_g_u_m_e_n_t_s: unit: The coordinate system in which to return the location of the mouse click. See the 'unit' function for valid coordinate systems. _D_e_t_a_i_l_s: This function is modal (like the graphics package function 'locator') so the command line and graphics drawing is blocked until the use has clicked the mouse in the current device. _V_a_l_u_e: A unit object representing the location of the mouse click within the current viewport, in the specified coordinate system. If the user did not click mouse button 1, the function (invisibly) returns 'NULL'. _A_u_t_h_o_r(_s): Paul Murrell _S_e_e _A_l_s_o: 'viewport', 'unit', 'locator' in package 'graphics', and for an application see 'trellis.focus' and 'panel.identify' in package 'lattice'. _E_x_a_m_p_l_e_s: 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() }