# Plotting graph using edge list

**URL:** <https://discourse.julialang.org/t/plotting-graph-using-edge-list/74541>\
**Category:** Graphs\
**Tags:** graphs\
**Created:** [January 13, 2022, 11:11am UTC](https://discourse.julialang.org/t/plotting-graph-using-edge-list/74541 "2022-01-13T11:11:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeffrey](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@Jeffrey](https://discourse.julialang.org/u/Jeffrey)\
**Post date:** [January 13, 2022, 11:11am UTC](https://discourse.julialang.org/t/plotting-graph-using-edge-list/74541/1 "2022-01-13T11:11:41Z")

</div>

Hi all.

I want to plot a SimpleDiGraph using an edge list and label the edges according to their position in my edge list. For example, if I run the following code

```julia
using Graphs, GraphPlot
edge_list = Edge.([(1, 3), (3, 2), (1, 2)])
g = SimpleDiGraph(edge_list)
display(gplot(g, nodelabel = 1:3, edgelabel = ["a", "b", "c"]))

```

I want edge (1,3) to have label “a”, (3,2) label “b” and (1,2) label “c”. However, the labeling is changed automatically to the order of the edges as they appear in collect(edges(g)). How can I circumvent this behaviour?

Related question: suppose I have edge\_list = Edge.([(1, 3), (3, 2), (1, 100)]). Then the graph will get 100 vertices, while I only want to have four, i.e. vertex 1, 2, 3 and 100. Is there an easy way to construct a directed graph, with the correct amount of vertices (that are also correctly labeled), in such a case?

---

<div class="post-metadata">

**Author:** ![etienne\_dg](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@etienne\_dg](https://discourse.julialang.org/u/etienne_dg)\
**Post date:** [January 13, 2022, 11:57am UTC](https://discourse.julialang.org/t/plotting-graph-using-edge-list/74541/2 "2022-01-13T11:57:09Z")

</div>

You can do something like this :  
`edges_to_label = Dict(Edge(1,3) => "a", Edge(3,2) => "b", Edge(1,2) => "c")`  
`display(gplot(g, nodelabel = 1:3, edgelabel = [edges_to_label[e] for e in edges(g)]))`

`SimpleGraph` only supports a unit range for the index of vertices, if you want to use your own labeling, you should use a MetaGraphs. (You can also have a look at `MetaGraphsNext` which is still experimental but should be more performant)
