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
  • 59,189
  • 14
  • 150
  • 185
lroca
  • 621
  • 2
  • 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
  • 119,832
  • 17
  • 199
  • 261