0

This is the function that is part of FactorMiner package

https://github.com/cran/FactoMineR/blob/master/R/plot.HCPC.R

As an example this is the code I ran

res.pca <- PCA(iris[, -5],  scale = TRUE)
hc <- HCPC(res.pca, nb.clust=-1,)

plot.HCPC(hc, choice="3D.map", angle=60)

3D map plot hc$call$X$clust <- factor(hc$call$X$clust, levels = unique(hc$call$X$clust)) plot(hc, choice="map") map plot

The difference is when i run this hc$call$X$clust <- factor(hc$call$X$clust, levels = unique(hc$call$X$clust)) before plot.HCPC this doesn't change the annotation in the figure but when I do the same thing before I ran this plot(hc, choice="map") it is reflected in the final output.

When i see the plot.HCPC function this is the line of the code that does embed the cluster info into the figure

for(i in 1:nb.clust) leg=c(leg, paste("cluster",levs[i]," ", sep=" "))
      legend("topleft", leg, text.col=as.numeric(levels(X$clust)),cex=0.8)

My question I have worked with small function where I understand when i edit or modify which one goes where and does what here in this case its a complicated function at least to me so Im not sure how do I modify that part and get what I would like to see.

I would like to see in case of my 3D dendrogram each of the cluster are labelled with group the way we can do in complexheatmap where we can annotate that are in row or column with a color code so it wont matter what the order in the data-frame we can still identify(it's just visual thing I know but I would like to learn how to modify these)

kcm
  • 200
  • 3
  • 13
  • 1
    The package is called `FactoMineR` not `FactorMiner`. – dipetkov Jul 17 '22 at 11:20
  • 1
    More importantly, you are mixing up classes with species. While it does happen that cluster 1 corresponds to Setosa, cluster 2 and cluster 3 do not in fact correspond neatly to Versicolor and Virginica. This is quite easy to see if you plot PC1 and PC2 and then color by species rather than by cluster. – dipetkov Jul 17 '22 at 11:22
  • "This is quite easy to see if you plot PC1 and PC2 and then color by species rather than by cluster. " so clustering PC is a bad idea then ..sorry for the typo `FactorMiner` – kcm Jul 17 '22 at 16:19
  • I didn't say clustering by PCs is a bad idea, necessarily. I'm pointing out that "cluster 1", "cluster 2" and "cluster 3" might sound like the wrong names but that's how clustering works in general: you get clusters and then you sometimes have to work hard to figure out what the clusters mean. – dipetkov Jul 17 '22 at 16:39
  • 1
    Here the red cluster is "mostly versicolor" and the green cluster is "mostly virginica". This is not quite the same as "all versicolor" and "all virginica". So actually the second plot is misleading, I think. – dipetkov Jul 17 '22 at 16:40
  • my simple idea was they way we annotate in complexheatmap either row or column clustering can we incorporate the same with that plot.HCPC function since it doens't take that species or group label in the column...because in heatmap its we provide external annotation which are mapped defined on given colors can same thing occur for plot.HCPC ? – kcm Jul 17 '22 at 17:11
  • 1
    Don't know complexheatmap (which you don't reference properly but seems to be a Bioconductor package not on CRAN). If this other package does what you need, why not use it instead? I'm not convinced that we should expect all packages to do all things. – dipetkov Jul 17 '22 at 17:15
  • Yes bioconductor package "I'm not convinced that we should expect all packages to do all things" that I thought but when i see the object generated from HCPC clustering the group labels are removed it is replaced by cluster1,cluster 2 etc. So i have to assign that label to those cluster, will try that . – kcm Jul 17 '22 at 17:50

0 Answers0