3

How can I add the sample ID (row number) as labels to each point in this LDA plot?

library(MASS)
ldaobject <- lda(Species~., data=iris)
plot(ldaobject, panel = function(x, y, ...) points(x, y, ...),
     col = as.integer(iris$Species), pch = 20)
csgillespie
  • 57,032
  • 13
  • 142
  • 178
lroca
  • 611
  • 1
  • 8
  • 19

1 Answers1

4

You can use text in the panel function:

library(MASS)
ldaobject <- lda(Species~., data=iris)
plot(ldaobject, 
     panel = function(x, y, ...) {
       points(x, y, ...)
       text(x,y,labels=seq_along(x),...) ## You change labels here 
      }
      ,
     col = as.integer(iris$Species), pch = 20)

enter image description here

agstudy
  • 116,828
  • 17
  • 186
  • 250