# Coloring of edges in Igraph

**URL:** <https://igraph.discourse.group/t/coloring-of-edges-in-igraph/802>\
**Category:** Usage\
**Tags:** R\
**Created:** [20 July 2021 15:26 UTC](https://igraph.discourse.group/t/coloring-of-edges-in-igraph/802 "2021-07-20T15:26:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Taqir](https://avatars.discourse-cdn.com/v4/letter/t/f9ae1b/32.png) [@Taqir](https://igraph.discourse.group/u/Taqir)\
**Post date:** [20 July 2021 15:26 UTC](https://igraph.discourse.group/t/coloring-of-edges-in-igraph/802/1 "2021-07-20T15:26:30Z")

</div>

Hello there,

I want to color the individual edges so that they take on the colors of the node they start from. Unfortunately my code doesn’t work.

![Beispiel_1X](https://global.discourse-cdn.com/free1/uploads/igraph/original/1X/addbc8fe9903867f2ea6fd506ac99acc52086cb2.png)

The code looks like this:

NEWC0 ← as.matrix(NEWC0)  
gnewc0 ← graph\_from\_adjacency\_matrix(NEWC0, mode=c(“directed”), weighted=TRUE, diag=FALSE, add.colnames=NULL, add.rownames=NA)  
E(gnewc0)$width ← E(gnewc0)$weight /5

**edge.start ← ends(gnewc0, es=E(gnewc0), names=F)[,1]**

**edge.col ← V(gnewc0)$color[edge.start]**

plot(gnewc0, vertex.color = c(“gray50”, “tomato”, “gold”, “blue”, “limegreen”, “orange”, “wheat”, “orchid”, “red”, “olivedrab”, “yellow”, “skyblue”, “darkmagenta”, “green”, “orangered2”, “darkslateblue”, “lightblue”), vertex.frame.color = “black”, vertex.label.cex = 0.9, vertex.label.color = “black”, vertex.label.distance = 200, vertex.label.font = 1, edge.arrow.size = 0.3, vertex.size = 12, vertex.frame.color=“black”, edge.curved=.1, **edge.color=edge.col** )

What should I change?

---

<div class="post-metadata">

**Author:** ![tamas](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/tamas/32/1261_2.png) [@tamas](https://igraph.discourse.group/u/tamas)\
**Post date:** [27 July 2021 09:13 UTC](https://igraph.discourse.group/t/coloring-of-edges-in-igraph/802/2 "2021-07-27T09:13:56Z")

</div>

I think the problem is that at the time when you execute `edge.col <- V(gnewc0)$color[edge.start]`, the vertices do not have any colors yet, so you simply assign `NA` to the edge colors. You first need to assign the colors to the vertices:

```auto
V(gnewc0)$color - c(“gray50”, “tomato”, “gold”, “blue”, “limegreen”, “orange”, “wheat”, “orchid”, “red”, “olivedrab”, “yellow”, “skyblue”, “darkmagenta”, “green”, “orangered2”, “darkslateblue”, “lightblue”)

```

and then you can assign the edge colors with `edge.col <- V(gnewc0)$color[edge.start]`
