Q:

r - how do you add a label to data points exceeding a certain value in a plot?

I want to add labels to data points in a scatter plot only if they exceed a specific value on the y axis. I can't figure out how to do this with the text() function. I'm new to r and any help is appreciated.

A:

Given a random sample of 10 values in a scatter plot:
values <- sample(10)
plot(values)

Labels can indeed be added to specific values with the text() function. The trick is to pass x and y arguments that correspond to the coordinates of those values. For example, this adds the label >5 to the right of each value greater than 5:
text(which(values > 5), values[values > 5], labels='>5', pos=4)

