Small-multiples plots in Plots.jl

I have time series for each state in the US. I have grouped the states by a geographic grouping factor. There are 8 state groups.

I’d like to make 8 panels, one for each state group, within the panel I want each state time series to be its own colored timeseries.

Imagine I have a dataframe like:

df = DataFrame(statecode = ["AK","AK",..."CA","CA"...], year = [...], stategroup = [1,1,...,2,2,...], measure = [...])

and I want something kinda like:

@df df plot(:year,:measure,group=(:stategroup,:statecode), layout=length(unique(df.stategroup)))

Except when I do that it just mixes states willy nilly not each group in its own panel.

How do I get that sort of thing?

Please check if this may help:

using DataFrames, StatsPlots

df = DataFrame(statecode=["AK","AK","CA","CA","TX","TX"], year=6:-1:1, stategroup=[1,1,2,2,1,1], measure=1:6)
N = length(unique(df.stategroup))
ylims = extrema(df.measure)
fig = plot(layout=N, legend=:topright)
gdf = groupby(df,:stategroup)
for i in 1:N
    @df gdf[i] plot!(fig[i],:year,:measure, group=(:stategroup, :statecode), ylims=ylims)
end
fig

ok, I think this is similar to what I wound up trying which was a list comprehension:

plot([plot(gr.year,gr.crudedeathrate ./ gr.baseline,group=gr.STUSAB,legend=:topleft,ylim=(0.0,2.5)) 
    for gr in groupby(bljoined,:stgroup)]...; size=(1000,1000),lineweight=4,xlab="Year",ylab="Relative Rate")