# Removing duplicate legend items

**URL:** <https://discourse.julialang.org/t/removing-duplicate-legend-items/78348>\
**Category:** General Usage\
**Tags:** plotting, plots\
**Created:** [March 23, 2022, 7:14pm UTC](https://discourse.julialang.org/t/removing-duplicate-legend-items/78348 "2022-03-23T19:14:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![b-fg](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@b-fg](https://discourse.julialang.org/u/b-fg)\
**Post date:** [March 23, 2022, 7:14pm UTC](https://discourse.julialang.org/t/removing-duplicate-legend-items/78348/1 "2022-03-23T19:14:34Z")

</div>

In `Plots.jl`, is it possible to scan the `Plot` object legend items so I can remove the ones that are duplicated? Thanks!

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [March 23, 2022, 8:50pm UTC](https://discourse.julialang.org/t/removing-duplicate-legend-items/78348/2 "2022-03-23T20:50:47Z")

</div>

Not sure if this is what you are looking for, but in case it helps:

```julia
using Plots; gr()

x = 1:10
p1 = plot(x, -x, label = "y = -x", c=:blue)
plot!(x, -x, label = "y = -x", c=:red)
plot!(x, 1 .- x, label = "y = 1 - x", c=:lime)

# this provides all series labels in the plot object p1:
labels = [x[:label] for x in p1.series_list]

# this removes repeated label 2 and makes line transparent:
p2 = deepcopy(p1)
p2.series_list[2][:label] = ""
p2.series_list[2][:linecolor] = RGBA{Float64}(0.0,0.0,0.0,0.0)
plot(p1, p2)

```

 ![Plots_gr_remove_repeated_legend](https://global.discourse-cdn.com/julialang/original/3X/5/e/5e19042d445ddff54f5e8e1a0c8e5175dcd37574.png)

---

<div class="post-metadata">

**Author:** ![b-fg](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@b-fg](https://discourse.julialang.org/u/b-fg)\
**Post date:** [March 24, 2022, 8:28am UTC](https://discourse.julialang.org/t/removing-duplicate-legend-items/78348/3 "2022-03-24T08:28:04Z")

</div>

Yeap, this would work! Thanks 🙂
