# Changing order in the legend

**URL:** <https://discourse.julialang.org/t/changing-order-in-the-legend/45158>\
**Category:** General Usage\
**Tags:** package, plotting, gaston\
**Created:** [August 18, 2020, 1:45pm UTC](https://discourse.julialang.org/t/changing-order-in-the-legend/45158 "2020-08-18T13:45:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![morkip](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@morkip](https://discourse.julialang.org/u/morkip)\
**Post date:** [August 18, 2020, 1:45pm UTC](https://discourse.julialang.org/t/changing-order-in-the-legend/45158/1 "2020-08-18T13:45:02Z")

</div>

I am creating a plot with multiple lines for comparison using `plot!(..)` for each new line. The line I plot first, appears at the very bottom of all the lines but at the first line of the legend. Obviously, it is very easy to get the reverse behaviour (on top of the other lines, but at the end of the legend). Is it somehow possible to make the first line I draw appear on top of the other lines AND at the same time in the first legend line?  
A google search didn’t bring up anything useful; I’d also be happy using hacky solutions. Thanks!

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [August 18, 2020, 3:04pm UTC](https://discourse.julialang.org/t/changing-order-in-the-legend/45158/2 "2020-08-18T15:04:41Z")

</div>

With [Gaston](https://github.com/mbaz/Gaston.jl):

```julia
using Gaston
plot(range(1,10,step=1),
     lc = :red,
     lw = 8,
     legend = :third,
     Axes(key = "center top invert"))
plot!(range(10,1,step=-1),
      lc = :blue,
      lw = 3,
      legend = :second)
plot!(range(3,8,length=10),
      lc = :black,
      lw = 3,
      legend = :first)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/0/f/0fb89978ace94421d774d6b04a221649f5534cdc.png)

First I configured the `key` (legend box in gnuplot parlance) with the `invert` option, and then I plotted the curves in reverse order.

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [August 18, 2020, 3:40pm UTC](https://discourse.julialang.org/t/changing-order-in-the-legend/45158/3 "2020-08-18T15:40:36Z")

</div>

You can just make an empty series with the same colour etc:  
`plot(1:0, lab="one", c=1); plot!(rand(10), lab="two", c=2, linewidth=5); plot!(rand(10), lab="", c=1, linewidth=5)`
