0
votes

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

1
You specified that the graph is undirected. Which way would the arrow point? Just leave off mode = 'undirected' - G5W
Thanks so much! I feel dumb for asking this now. - anticavity123
We all miss things. I am glad to help. - G5W

1 Answers

0
votes

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/