Get Coordinates from Plot

DESCRIPTION:

Returns the coordinates specified interactively on a plot under certain graphics device drivers. Points and/or lines may be added to the plot.

USAGE:

locator(n=500, type="n")

OPTIONAL ARGUMENTS:

n
the maximum number of points to locate.
type
character describing interactive drawing option. If type is "n", nothing is drawn. Values of "p", "l", "b", and "o" plot points at the digitized coordinates, lines connecting them, both points and lines, or overplotted points and lines.

VALUE:

list containing vector components x and y, which give coordinates for each point. The length of these vectors is at most n, but can be shorter if the user terminates graphic input after fewer than n points are given. If the user terminates the graphic input before selecting any vector, the function returns numeric(0), rather than list(x=numeric(0),y=numeric(0)) .

SIDE EFFECTS:

if type does not equal "n", then points and/or lines are added to the current plot.

DETAILS:

When using the motif driver under the X Window System, a point is identified by positioning the cursor over the point and pressing the left mouse button. To exit locator, press the middle button (both buttons on a two button mouse) while the cursor is in the graphics window. This function may also be used with the "tek14" drivers.

Some devices that don't allow real interaction will prompt you for an x,y pair.

We do not recommend the use of locator or identify to pause between pages when showing a series of graphs. Instead use ask=T in the plotting commands.

WARNING:

Remember that you must locate n points or exit locator in order to be able to get back to the S-PLUS prompt.

SEE ALSO:

, .

EXAMPLES:

# user points at an outlier which is then labelled
plot(1:10, rt(10, 1))   # some cauchy data
text(locator(1), "outlier")
# position a legend
legend(locator(1), legend=c("IBM", "AT&T", "GM"), fill=2:4)
lines(locator())    # input a number of points, connect with line
locator(type="l")    # alternative