Reputation: 111
I am creating a network graph in R using the igraph library. The input data is an adjacency matrix. However, there are no edge arrows connecting the vertices.
My weighted adjacency matrix looks something like this:
A B C
A 0 3 5
B 2 0 6
C 0 7 0
This is my code in R:
net <- graph.adjacency(adj_matrix, mode = 'undirected', weighted = TRUE,
diag = FALSE)
plot(net)
I am quite new to this. I thought that the vertices would be plotted according to my matrix and that the edge arrows will map the relationships (i.e. there should be an arrow connecting A to B since the (A,B)th index is non-zero).
Am I missing something here?
Thanks
Upvotes: 0
Views: 1527
Reputation: 49
You need to convert your adjacency matrix to the edge data format, using the following code: network=graph_from_adjacency_matrix( adj_matrix, weighted=T, mode="undirected", diag=F)
please check this link for detail: https://www.r-graph-gallery.com/250-correlation-network-with-igraph/
Upvotes: 0