Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linear discriminant analysis plot

Tags:

plot

r

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)
like image 531
lroca Avatar asked Nov 23 '25 15:11

lroca


1 Answers

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

like image 62
agstudy Avatar answered Nov 26 '25 04:11

agstudy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!