In this case, everything is ok:
x <- 1:10
y <- x^3
plot(x, y)
identify(x, y)
But, using qplot there are some troubles:
x <- 1:10
y <- x^3
qplot(x, y)
identify(x, y)
Does anybody know a similar command or other way to label specific points in ggplot2 graphs?
Here is a method that works using only the
gridandggplot2packages:If you want a text label instead of the number your could replace
win the call togrid.textwith something likeletters[w](or whatever vector of labels you want).If you are going to be doing several of these then you could wrap this in a function with the last few lines possibly in a loop. You could also add addtional logic to warn if you don’t click near a point (like identify does) or to move the label closer or further from the point (this version places the label for the nearest datapoint at the point that you click).