0

Using HCPC, a function of FactoMineR for clustering, how can we change the text legend of an HCPC plot? Exactly, how to change "cluster 1","cluster 2" etc. with a text vector we specified (legend.txt as a vector) Here the code which works

cai<-PCA(iris[,-5]) 
res.hcpc2 <- HCPC(pcai, graph = FALSE)
plot(res.hcpc2, choice = "3D.map", title= "mapping site clusters "))

enter image description here If we try to change the legend

leg.txt <- c("SE", "VE", "VI") 
plot(res.hcpc2, choice = "3D.map", title= "mapping site clusters ", legend=leg.txt))

we get an error message "legend is not a graphical parameter", and the text of the legend is not changed. Thanks

catindri
  • 384
  • 5
  • 14

1 Answers1

0

You should mention in your question that HCPC is a function in the FactoMineR package. Looking at the manual page for plot.HCPC in the package I do not see any way to modify or suppress the default legend, but you should contact the package maintainer, maintainer("FactoMineR"), to be sure. You can use a kludge to overwrite the default legend as follows:

 legend("topleft", c("SE", "VE", "VI"), bg="white", pch=16, col=1:3,
      text.col=1:3, text.width=1.1, cex=.8)

The problem is that the box is larger than it needs to be. This version will just print the legend without a box:

legend("topleft", c("SE", "VE", "VI"), bg="white", pch=16, col=1:3,
     text.col=1:3, text.width=1.3, cex=.8, box.col="white", xpd=NA)
dcarlson
  • 10,936
  • 2
  • 15
  • 18
  • https://stackoverflow.com/questions/72958698/adding-group-information-to-3d-plot-in-factoextra I have pretty much similar question is there way to add metadata information here ? – PesKchan Jul 14 '22 at 20:43