How to make one legend entry for same colour?

Is there a way to make one legend entry per colour? I’d like to specify that green represents plants and brown represents nutrients. I am using Plots.jl

image

MWE

foo = 1:10; bar = rand(10, 2)
my_plot = plot(foo, bar)
bart = rand(10)
plot!(my_plot, foo, bart,color=1)

image

So I’d like to have one legend entry for orange and one for blue, even though it plots foo and bart.

You could just plot the first line of each colour separately and provide a label, then pass an empty label to subsequent plot calls with that colour:

plot(1:10, rand(10), color = 1, label = "Blue")
plot!(1:10, rand(10), color = 2, label = "Orange")

for _ in 1:10
    plot!(1:10, rand(10), color = 1, label  = "")
end

Is this still the only way around this?

As far as I know it is.