# How to add metadata such as labels to nodes in Graphs.jl?

**URL:** https://discourse.julialang.org/t/how-to-add-metadata-such-as-labels-to-nodes-in-graphs-jl/84513
**Category:** Graphs
**Tags:** question, graphs
**Created:** [July 20, 2022, 6:59am UTC](https://discourse.julialang.org/t/how-to-add-metadata-such-as-labels-to-nodes-in-graphs-jl/84513 "2022-07-20T06:59:52Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![tiZ](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tiz/32/211800_2.png) [@tiZ](https://discourse.julialang.org/u/tiZ)
#### Post date: [July 20, 2022, 6:59am UTC](https://discourse.julialang.org/t/how-to-add-metadata-such-as-labels-to-nodes-in-graphs-jl/84513/1 "2022-07-20T06:59:52Z")

</div>

Hi, I wonder if there some convenient way to add the labels to nodes in a graph, I’m using Graphs.jl currently.

I have try to record the (node Number =\> label) in a separated dictionary, but I think the order of nodes number will be change if any node removed or added, so, is there any suggestion to attach a label to the node?

Thanks for any suggestion.

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [July 20, 2022, 7:12am UTC](https://discourse.julialang.org/t/how-to-add-metadata-such-as-labels-to-nodes-in-graphs-jl/84513/2 "2022-07-20T07:12:54Z")

</div>

The recommended package for that would be [MetaGraphsNext.jl](https://github.com/JuliaGraphs/MetaGraphsNext.jl), but it is a little rough around the edges. [MetaGraphs.jl](https://github.com/JuliaGraphs/MetaGraphs.jl) is an older and more stable but less efficient version

---

<div class="post-metadata">

### Author: ![tiZ](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tiz/32/211800_2.png) [@tiZ](https://discourse.julialang.org/u/tiZ)
#### Post date: [July 20, 2022, 8:06am UTC](https://discourse.julialang.org/t/how-to-add-metadata-such-as-labels-to-nodes-in-graphs-jl/84513/3 "2022-07-20T08:06:51Z")

</div>

Thanks for you help!  
I have try both [MetaGraphsNext.jl](https://github.com/JuliaGraphs/MetaGraphsNext.jl) and MetaGraphs.jl, but I met the error:

```julia
julia> typeof(g)
SimpleGraph{Int64}   

julia> G = MetaGraph(g)      
ERROR: MethodError: no method matching LightGraphs.SimpleGraphs.SimpleGraph(::SimpleGraph{Int64})     

```

I have installed the packages as below:(they have entry on JuliaGraphs website)

```julia
MetaGraphsNext v0.3.0
MetaGraphs v0.7.1  
Graphs v1.7.1

```

it is confused, do both packages only work with LightGraphs.jl instead of Graphs.jl currently?

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [July 20, 2022, 8:48am UTC](https://discourse.julialang.org/t/how-to-add-metadata-such-as-labels-to-nodes-in-graphs-jl/84513/4 "2022-07-20T08:48:05Z")

</div>

You’re only supposed to use one of these packages at a time. Can you provide a complete reproducible example (with imports) so I can take a look?

---

<div class="post-metadata">

### Author: ![tiZ](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tiz/32/211800_2.png) [@tiZ](https://discourse.julialang.org/u/tiZ)
#### Post date: [July 20, 2022, 12:21pm UTC](https://discourse.julialang.org/t/how-to-add-metadata-such-as-labels-to-nodes-in-graphs-jl/84513/5 "2022-07-20T12:21:42Z")

</div>

It is my stupid mistake, I did load two packages. 🙃

It works fine now. Thanks for your wonderful pacakge. It saves my time.
