The R code for this example is a little longer than that of the simpler examples. The basic idea is that we put a scatter plot in a Tk window, using the tkrplot package by Luke Tierney. We then allow the user to click on (or near) one of the plotted points in order to attach a label to that point (and replot the graph).
The hardest part is mapping between image (Tk widget) coordinates and R plot coordinates, which is done in the function onLeftClick().
Running the code below gives the following graph window:
Clicking on the upper-left point gives the following message box:
After answering Yes to the message box question, the graph is updated. Note the label, A above the point that was clicked on.
After labeling all of the points, the graph looks like this: