The function identify() allows to click on points in a scatterplot to add labels. R can automatically determine the "position" next to the point where the label should occur. Also, the distance of the label can be defined (offset) and color, font, and size of the labels can be given. However, except for coordinates and labels all other arguments must be single values, referring to all the points to be labelled.

I am looking for a way to label points in a plot (quite like by identify()) but with different colors and offsets for each point. Example (does not work):

plot(x=1:3,y=1:3,col=1:3) # three points in three colors

identify(x=1:3,y=1:3,labels=1:3,col=1:3) # *should show the labels in the same colors like the points*

The example throws the error-message "Error in par(extras) : graphical parameter "col" has the wrong length" (it must be of length 1)

I know I could call identify() to get the point indices and label-positions and then plot the labels as text. But during the ident()-call I have no control which points are already selected.

If I call identify() repeatedly for a single point and then draw the text, but I hope there is a more elegant way. Any ideas?

More Jochen Wilhelm's questions See All
Similar questions and discussions