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.
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.