How to label points on a scatterplot with R? How to label points on a scatterplot with R? r r

How to label points on a scatterplot with R?


You can easily create this by using the text() function.

text(x,y,labels=names)


You could do it in ggplot2:

require(ggplot2)d <- data.frame(x = c(102856,17906,89697,74384,91081,52457,73749,29910,75604,28267,122136, 54210,48925,58937,76281,67789,69138,18026,90806,44893), y = c(2818, 234, 2728, 2393, 2893, 1015, 1403, 791, 2243, 596, 2468, 1495, 1232, 1746, 2410, 1791, 1706, 259, 1982, 836), names = c("A","C","E","D","G","F","I","H","K","M","L","N","Q","P","S","R","T","W","V","Y"))ggplot(d, aes(x,y)) + geom_point() + geom_text(aes(label=names))

You might want the text labels not to be directly on top of the points, which you could accomplish by using the hjust or vjust arguments in the geom_text part.


You do not need the calibrate package. You can do:

text (x, y-50, names)

It does work for me.