Reputation: 58
I have a CSV format like this one (representing an adjacency matrix of a graph):
0,0,3.16023,7.98319,4.97476,0,0,7.5256,0,3.61683
0,0,0,0,6.66346,3.78653,0,0,0,5.28698
3.16023,0,0,9.30634,0,0,0,0,6.97926,6.94043
7.98319,0,9.30634,0,7.83085,0,0,6.32612,3.90679,0
4.97476,6.66346,0,7.83085,0,1.72829,4.3236,0,9.29742,0
0,3.78653,0,0,1.72829,0,5.51931,0,0,1.70871
0,0,0,0,4.3236,5.51931,0,0,9.81537,0
7.5256,0,0,6.32612,0,0,0,0,4.16524,0
0,0,6.97926,3.90679,9.29742,0,9.81537,4.16524,0,5.78895
3.61683,5.28698,6.94043,0,0,1.70871,0,0,5.78895,0
And I use R and igraph library to plot it.
library(igraph)
mygraph=read.csv("graph.csv", header=FALSE)
M <- as.matrix(mygraph)
g <- graph.adjacency(adjmatrix=M, mode="undirected", weighted=TRUE, diag=FALSE)
plot(g)
How can I print the edge lengths/weights? The graph (https://i.sstatic.net/X6pkw.png) is plotted without the edge lengths. How can I print inside the plot the edge lenghts?
Upvotes: 1
Views: 1573
Reputation: 10825
plot(g, edge.label=round(E(g)$weight, 3))
See ?igraph.plotting
in the manual.
Upvotes: 2