Introduction

With a few exceptions of some particular functions, R does not really offer highly any highly interactive graphics. (See this document for some extension/libraries and information on software that collaborates with R).

R functions

R has several basic functions to interact with graphics and create simple interactive tools, namely the identify() and locator() (returns the position of a click in a graph window) functions. This last function is useful when you program; no details will be discussed here. The goal here is to illustrate the use of the identify function in a number of examples. Note that these functions work best with scatterplots..

The sequence
plot(urb,infmor)
identify(urb,infmor,labels=rownames(world))
displays a cloud of points on which you can identify observations with a click of the mouse (cursor shows a cross). To stop this, use the context-menu of your mouse displaying or the Stop button shown in the toolbar area of the graphics window. (Esc to abort.)

When terminating, the function returns the indices to the observations you have identified, e.g.

[1]   1   7  46  65  67 143 148
(note when you abort the identification the function returns no value).

The index to the selected observations can be used in other functions for further examination of these observations. The example below produces a histogram of variable gnpserv on the observations that have been selected on the plot showing the relationship between urb and infmor

 plot(urb,infmor)
 hist(gnpserv[identify(urb,infmor,labels=rownames(world))])
Package lattice

In {lattice} you will find a function, analogous to identify: panel.identify. In contrast to identify, no need to specify coordinates; however the panel on which you wish to identify observations needs to be designated using trellis.focus.

xyplot(urb ~ infmor | continent)
trellis.focus("panel",1,2)
panel.identify(labels=rownames(world))

Although there is only one panel, it must be designated.

bwplot(area)
trellis.focus("panel", 1, 1)
panel.identify(labels=rownames(world))