How to put the specimen ID in the graphics


Welcome to the RStudio community!

I'm not familiar with the gpagen function, so I don't know what the data frame looks like, but normally the approach you took should work, unless there is are no rownames in the data frame. Here is a working example

myData = data.frame(x = 1:10, y = runif(10), row.names = letters[1:10])

plot(myData$x, myData$y)
text(myData$x, myData$y, rownames(myData), offset = 0.3, pos = 4)

Created on 2020-08-10 by the reprex package (v0.3.0)

Make sure the gpa$coords object is a dataframe with rownames. If you keep having trouble, create a reprex so we can run your code. A reprex consists of the minimal code and data needed to recreate the issue/question you're having. You can find instructions how to build and share one here:

Finally, you could consider using ggplot instead of the basic plot function, as this is way move powerful and versatile. The geom_label or geom_text will do the trick there.

Hope this helps,

1 Like