I am using igraph to map a directed network graph from an edge list (I used “graph_from_data_frame”). The edge list table has two columns - “source” and “target” - my question is, when I turn the “directed = TRUE”, how will igraph handle the direction between edges? will it just identify the first column as “from” and the second column as “to”? or there is a different machanism?
Yes, the first two columns are the source and target vertices of edges. The rest are treated as edge attributes. Here is the source code:
You can find additional documentation by typing into R:
>help(help)
>help(igraph)
>help(graph_from_data_frame)
This is extremely helpful. Example mentioned:
actors <-
data.frame( name = c("Alice", "Bob", "Cecil", "David", "Esmeralda")
, age = c(48,33,45,34,21)
, gender= c("F","M","F","M","F")
)
relations <-
data.frame( from =c("Bob", "Cecil", "Cecil", "David", "David", "Esmeralda")
, to =c("Alice", "Bob", "Alice", "Alice", "Bob", "Alice")
, same.dept =c(FALSE,FALSE,TRUE,FALSE,FALSE,TRUE)
, friendship =c(4,5,5,2,1,1), advice=c(4,5,5,4,2,3)
)
g <- graph_from_data_frame(relations, directed=TRUE, vertices=actors)
print(g, e=TRUE, v=TRUE)
You can find additional info trying this:
print.default(g)
g
V(g)$name
E(g)$same.dept
plot(g, layout=layout_with_sugiyama)
1 Like