Search code examples
rmatrixvisualizationsimilarity

Transform and Visualize Similarity Matrix in R


I'm working with a matrix that contains several entries and their similarity in the following format:

//      A      B      C  

 A      1     0.8    0.4

 B      0.8    1     0.2

 C      0.4   0.2     1

In this case, 1 means that two entries are identical, 0 that they are completely different. Each entry represents one string of observations that are either present or not. The similarity value is calculated by checking for overlapping observations. I would like to visualize this relation of the different entries; would it be possible to use a dendrogram in this case?


Solution

  • Here are two ways to visualize your matrix.

    1. corrplot

      library(corrplot)
      corrplot(Mat)

    corrplot

    1. dendrogram using hclust

    Your matrix is similarity but for hclust, we need dis similarity, so I will transform it using 1 - Mat.

    HC = hclust(as.dist(1-Mat))
    plot(HC)
    

    Dendrogram