# how does igraph identify direction between edges

**URL:** <https://igraph.discourse.group/t/how-does-igraph-identify-direction-between-edges/1324>\
**Category:** Usage\
**Tags:** R\
**Created:** [11 August 2022 17:12 UTC](https://igraph.discourse.group/t/how-does-igraph-identify-direction-between-edges/1324 "2022-08-11T17:12:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bc34556](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/bc34556/32/810_2.png) [@bc34556](https://igraph.discourse.group/u/bc34556)\
**Post date:** [11 August 2022 17:12 UTC](https://igraph.discourse.group/t/how-does-igraph-identify-direction-between-edges/1324/1 "2022-08-11T17:12:28Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [11 August 2022 19:27 UTC](https://igraph.discourse.group/t/how-does-igraph-identify-direction-between-edges/1324/2 "2022-08-11T19:27:14Z")

</div>

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:

> <https://github.com/igraph/rigraph/blob/dev/R/data_frame.R#L173>

---

<div class="post-metadata">

**Author:** ![KeesP](https://avatars.discourse-cdn.com/v4/letter/k/2bfe46/32.png) [@KeesP](https://igraph.discourse.group/u/KeesP)\
**Post date:** [11 August 2022 19:41 UTC](https://igraph.discourse.group/t/how-does-igraph-identify-direction-between-edges/1324/3 "2022-08-11T19:41:57Z")

</div>

You can find additional documentation by typing into R:

```auto
>help(help)
>help(igraph)
>help(graph_from_data_frame)

```

This is extremely helpful. Example mentioned:

```auto
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:

```auto
print.default(g)
g
V(g)$name
E(g)$same.dept
plot(g, layout=layout_with_sugiyama)

```
