1

I have a symmetric matrix which I modified a bit: Sample Data

The above matrix is a symmetric matrix except the fact that I have added values in diagonal too (will tell the purpose going forward)

This matrix represents that how many times a person (A, B, C, D, E) works with other person on a publication. e.g. B and C worked 3 times together, similarly A and E worked 4 times together. Now the diagonal values represents how many times a person worked individually e.g. B worked on 4 publications (either alone or with someone else) similarly C worked on 3 publications.

Now I want to make a network analysis graph in R which describes relation between different person in terms of edge thickness and node size. e.g. the graph should look like this:

Final Graph

In graph, node circle size depends on number of publications a person worked on, e.g. circle B is largest as its diagonal value is maximum and A & E are smallest as they have lowest diagonal values. Also, the edge thickness between nodes depends on how many times they worked together, e.g. edge thickness between A & E is maximum as they worked 4 times together, compared to edge thickness (lesser than edge thickness between A & E) between B & C as they have worked 3 times together.

I can describe the relation between two persons basis edge thickness, however inclusion of diagonal values creating problems for me. Is it possible to do it in R? Any leads would be highly appreciated

Pardeep Naik
  • 99
  • 1
  • 12
  • You could show the diagonal as a self-loop. In igraph this would be an edge between one and the same circle (so from A to A for example). Maybe this helps: https://stackoverflow.com/questions/30066255/how-to-create-self-loop-in-igraph-r – TinglTanglBob Mar 29 '19 at 16:12
  • Just for clarification: The diagonal represents the numbers of puplications a person worked alone or the number of puplications a person worked on alone or together with other over all? In case of the later, the values are a bit confusing. Person A would have worked on 1 puplication over all but worked on 2 puplications together with person B. – TinglTanglBob Mar 29 '19 at 16:19
  • It is the later case, but I added the values randomly to create the sample data to make question clearer. Apologies for creating confusion. Original data would have been huge and confusing. – Pardeep Naik Mar 29 '19 at 19:25
  • No need for apologies here :) – TinglTanglBob Mar 29 '19 at 21:32

1 Answers1

1

You can do this with the igraph package. Because the diagonal means something different from the other entries in the matrix, I have separated the matrix into two pieces, the diagonal and the rest.

Your data

SM = as.matrix(read.table(text="A B C D E
    1 2 1 1 4
    2 4 3 2 1
    1 3 3 1 2
    1 2 1 2 1
    4 1 2 1 1",
header=TRUE))
rownames(SM) = colnames(SM)

library(igraph)

AM = SM
diag(AM) = 0
D = diag(SM)

g = graph_from_adjacency_matrix(AM, 
    mode     = "undirected",
    weighted = TRUE)
plot(g, 
    edge.width=E(g)$weight, 
    vertex.size = 10+3*D)

Weighted graph

G5W
  • 36,531
  • 10
  • 47
  • 80