locator() is usually called with no arguments. It is particularly useful for interactively selecting positions for graphic elements such as legends or labels when it is difficult to calculate in advance where the graphic should be placed. For example, to place some informative text near an outlying point, the command
text(locator(1), "Outlier", adj=0)
may be useful. locator() will still work if the current device does not support a mouse; in this case the user will be prompted for x and y coordinates.
Sometimes we want to identify particular points on a plot, rather than their positions. For example, we may wish the user to select some observation of interest from a graphical display and then manipulate that observation in some way. Given a number of (x,y) coordinates in two numeric vectors x and y, we could use the identify() function as follows:
plot(x,y)
identify(x,y)
The identify() functions performs no plotting itself, but simply allows the user to move the mouse pointer and click the left mouse button near a point. The point nearest the mouse pointer will be highlighted with its index number (that is, its position in the x/y vectors) plotted nearby. Alternatively, you could use some informative string (such as a case name) as a highlight by using the labels argument to identify(), or disable highlighting altogether with the plot=F argument. When the middle button is pressed, identify() returns the indices of the selected points; you can use these indices to extract the selected points from the original vectors x and y.