1

I am trying to find a way to implement this in R as shown in this link Correlation Heatmaps with Hierarchical Clustering. Essentially, the most interesting aspect where I am seeking to apply is the part that allows one to set a threshold as executed with the fcluster function in python. I am not aware if such function actually exist in R. I will be soo glad if someone with the skill in python and R could help me with that. Thanks for the assistance!

from scipy.spatial.distance import squareform

plt.figure(figsize=(12,5))
dissimilarity = 1 - abs(correlations)
Z = linkage(squareform(dissimilarity), 'complete')

dendrogram(Z, labels=data.columns, orientation='top', 
           leaf_rotation=90)
# Clusterize the data
threshold = 0.8
labels = fcluster(Z, threshold, criterion='distance') # obtain the clusters
Quamena
  • 59
  • 5
  • Does this answer you question? https://stackoverflow.com/questions/5453336/plot-correlation-matrix-into-a-graph – jay.sf Jan 09 '22 at 09:16
  • As an alternative or workaround, you could try and use the `reticulate` package in R, which allows you to use python packages to (for example) create the dendrogram and then you can plot it in R (Useful when certain functions exist in R, but not in python). This link might also be helpful https://stackoverflow.com/questions/40474774/heatmap-dendrogram-based-on-correlation-in-r – thehand0 Jan 09 '22 at 12:06
  • @Jay.sf That's a nice piece of information but that is not exactly what I wanted. – Quamena Jan 09 '22 at 23:38
  • 1
    @thehand0. I'll give it a trial. Thanks! – Quamena Jan 09 '22 at 23:42

0 Answers0