9

I am using igraph in R for network analysis. I want to display an edge attribute on each line in the plot. An example is below

df <- data.frame(a = c(0,1,2,3,4),b = c(3,4,5,6,7))
nod <- data.frame(node = c(0:7),wt = c(1:8))
pg <- graph_from_data_frame(d = df, vertices = nod,directed = F)
plot(pg)

I want the value of the "wt" feature to show up between each node on the line, or preferably, in a little gap where the line breaks.

Is it possible to make this happen?

user2997345
  • 121
  • 1
  • 2

1 Answers1

15

Use the parameter edge.label to assign labels of the edges, I used - probably wrong - nod$wt. Of course, you could assign other labels.

You could use the following code:

# load the package
library(igraph)

# your code
df <- data.frame(a = c(0,1,2,3,4),b = c(3,4,5,6,7))
nod <- data.frame(node = c(0:7),wt = c(1:8))
pg <- graph_from_data_frame(d = df, vertices = nod,directed = F)

# plot function with edge.label added
plot(pg, edge.label = nod$wt)

Please, let me know whether this is what you want.

KoenV
  • 4,113
  • 2
  • 23
  • 38