1

I have the correlation coefficients matrix as bellow and am trying to visualize this using igraph package and its layouts. None of the layouts output a clear network. Can anyone suggest how I can fix this?

dput(adjm)
structure(c(1, 0.963441407633081, 0.986207962169263, 0.979240565034286, 
0.260477742974566, 0.928971036770817, 0.990859133037916, 0.98615828324931, 
0.923912532530861, -0.328655580485871, 0.963441407633081, 1, 
0.977343669695317, 0.973832136657044, 0.251853284084679, 0.941236887557877, 
0.970317460375686, 0.979203650433608, 0.931475199702801, -0.262254189238524, 
0.986207962169263, 0.977343669695317, 1, 0.978059833099735, 0.241345600979638, 
0.934105190260024, 0.991280098453041, 0.987744430218514, 0.923127024136395, 
-0.287964556946545, 0.979240565034286, 0.973832136657044, 0.978059833099735, 
1, 0.246299519388515, 0.945461616197224, 0.980265015416377, 0.988163901155937, 
0.942210041798293, -0.304138745456209, 0.260477742974566, 0.251853284084679, 
0.241345600979638, 0.246299519388515, 1, 0.175351977633108, 0.254175573791427, 
0.241722979690123, 0.200038950214348, -0.622365632769871, 0.928971036770817, 
0.941236887557877, 0.934105190260024, 0.945461616197224, 0.175351977633108, 
1, 0.930342825056357, 0.94185467129245, 0.963675695468988, -0.238684953080287, 
0.990859133037916, 0.970317460375686, 0.991280098453041, 0.980265015416377, 
0.254175573791427, 0.930342825056357, 1, 0.988245057126345, 0.924562105692743, 
-0.305337729938945, 0.98615828324931, 0.979203650433608, 0.987744430218514, 
0.988163901155937, 0.241722979690123, 0.94185467129245, 0.988245057126345, 
1, 0.936651970737347, -0.294420287372996, 0.923912532530861, 
0.931475199702801, 0.923127024136395, 0.942210041798293, 0.200038950214348, 
0.963675695468988, 0.924562105692743, 0.936651970737347, 1, -0.270230372039959, 
-0.328655580485871, -0.262254189238524, -0.287964556946545, -0.304138745456209, 
-0.622365632769871, -0.238684953080287, -0.305337729938945, -0.294420287372996, 
-0.270230372039959, 1), .Dim = c(10L, 10L), .Dimnames = list(
    c("jpm", "gs", "ms", "bofa", "schwab", "brk", "wf", "citi", 
    "amex", "spgl"), c("jpm", "gs", "ms", "bofa", "schwab", "brk", 
    "wf", "citi", "amex", "spgl")))

g <- graph_from_adjacency_matrix(adjm, weighted=T, mode="undirected", diag=F)
plot(g, layout=layout_nicely)
statwoman
  • 380
  • 1
  • 9
  • 1
    Are you sure what you have there is an adjacency matrix? For example, they typically consist of 1's and 0's, with 0's on the diagonal. What you have looks more like correlation coefficients. – David Clarke Jun 22 '21 at 00:09
  • Yeah you are correct, it's not the adjacency matrix, it's the correlations which would count as the weights. I will edit that. @DavidClarke – statwoman Jun 22 '21 at 00:14

1 Answers1

1

You can try the code below

g <- graph_from_adjacency_matrix(adjm, weighted = "wt", mode = "undirected", diag = F)
plot(g, edge.label = round(E(g)$wt, 2))

where the weights as a edge attribute is named as wt in graph_from_adjacency_matrix. Then, when you plot g, you can specify that you want to print wt as the edge labels by edge.label = round(E(g)$wt, 2).

enter image description here

ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81