How to make a groupedbar plot with several stacked bars

I think I wasn’t clear with what I wanted to do. In any case, here’s my code in it’s entirety to show what I ended up doing. It’s not a minimal working example, it’s just there as guidance for anyone else who wants to try doing this.

My main things to solve my problems were:

  1. The series colour repeats, so if you have 30 series and 6 colours then you will get 6 colours repeated 5 times in the order you specify
  2. I used an empty plot to make a custom legend

You can find an example picture at the bottom.

GRP = gep.GRP; P = gep.P; T = gep.T; L⁺ = gep.L⁺
    nRP = length(GRP) # Number of reserve providers
    nL = length(L⁺)

    rL⁺ = gep[:rL⁺].data
    curtL⁺ = gep[:curtL⁺].data
    LSL⁺ = reshape(gep[:LSL⁺].data, (1,size(gep[:LSL⁺])...))
    reserves = cat(rL⁺, curtL⁺, LSL⁺; dims=1)
    y = fill(0.0, length(L⁺)*length(GRP), length(P), length(T))
    y2 = fill(0.0, length(L⁺), length(P), length(T)) # Reserve level line plots
    for p = P
        for t = T
            for l = L⁺
                for g = 1:nRP
                    y[(l-1)*nRP+g,p,t] = reserves[g,l,p,t]
                end
            end
            for l = L⁺[2:end]
                y2[l,p,t] = y2[l-1,p,t] + sum(reserves[:,l,p,t])
            end
        end
    end

    seriescolor = [:red :blue :orange :yellow :green :purple]

    # Shorten depending on number of reserve providers
    seriescolor = seriescolor[:,1:nRP]

    # Plot the differentiated reserves
    p1 = groupedbar(y[:,p,:]', legend=:none, bar_width=1, bar_position=:stack, seriescolor=seriescolor, xlabel="Timestep", ylabel="Reserves (MW)", linewidth=0)

    # Plot the reserve level lines
    plot!(p1, T, y2[:,p,:]', seriescolor=:black, linewidth=2)

    # Do some hacky shit for the legend
    empty = fill(0.0, 1, nRP)
    p2 = plot(1, empty, lab=GRP, legend=:best, grid=false, showaxis=false, ylims=(1,2), seriescolor=seriescolor, linewidth=6)

    # Plot everyting
    l = @layout [a{0.8w} b{0.2w}]
    plot(p1, p2, layout=l)