Home > Mobile >  Representing a correlation matrix without a "classical" heatmap
Representing a correlation matrix without a "classical" heatmap

Time:01-27

I'm doing some analysis on a complex network. I have computed the degree correlation matrix, which looks like this:

data[1:5, 1:5] 

    1  2  3  4  5
1   6 19 11 16  5
2  19 10 16 12  6
3  11 16  7 11 10
4  16 12 11  5  9
5   5  6 10  9  8

And I'd like to plot it to obtain something akin to this: plot

I've tried to use ggplot but the results are not at all satisfying, this is my code:

library(reshape2)
library(ggplot2)
data = melt(data) 
#The "melt" function was used to turn the matrix in a three column dataframe with columns named "Var1",
"Var2", and "value"

ggplot(data = data)  
theme_bw()  
geom_tile(aes(x = Var1, y = Var2, fill = value))  
scale_fill_viridis(name = "")  
labs(x = "k2", y = "k1")

And this is what I get:

plot2

Is there any way to fix it?

P.S. Sorry if I couldn't post the images directly, but my reputation is not high enough

EDIT: I'm putting here the dput() output of my matrix, as asked in the comments:

structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), dim = c(75L, 75L), dimnames = list(
    c("2", "3", "5", "6", "7", "8", "9", "10", "11", "12", "13", 
    "14", "15", "16", "18", "19", "20", "21", "22", "23", "24", 
    "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", 
    "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", 
    "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", 
    "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", 
    "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", 
    "75", "77", "79", "81"), c("2", "3", "5", "6", "7", "8", 
    "9", "10", "11", "12", "13", "14", "15", "16", "18", "19", 
    "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", 
    "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", 
    "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", 
    "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", 
    "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", 
    "70", "71", "72", "73", "74", "75", "77", "79", "81")))

CodePudding user response:

You get the lines because you have missing values. The full range is not represented in your data. Here's one way to fill in the missing values using tidyr

library(dplyr)
library(tidyr)

full_range <- function(x) seq(min(x), max(x))
data %>% 
  as.data.frame() %>% 
  tibble::rownames_to_column("Var1") %>% 
  pivot_longer(-Var1, names_to="Var2") %>% 
  mutate(across(Var1:Var2, as.numeric)) %>% {
    d <- .
    expand_grid(Var1=full_range(d$Var1), Var2=full_range(d$Var2)) %>% 
      left_join(d) %>% 
      replace_na(list(value=0))
  } %>% 
  ggplot()  
  theme_bw()  
  geom_tile(aes(x = Var1, y = Var2, fill = value))  
  scale_fill_viridis_c(name = "")  
  labs(x = "k2", y = "k1")

that looks like this enter image description here

  • Related