Plotting by multiple factors

You can use grouped dataframes and loop over these.
As there are only two groups in your example, the code below writes it explicitly without a loop:

gdf = groupby(df, :function)
fig = plot(layout=(2,1), legend=:topleft)
@df gdf[1] plot!(fig[1],:x, :y, group=(:function, :p1, :p2), ylims=(0,20))
@df gdf[2] plot!(fig[2],:x, :y, group=(:function, :p1, :p2), ylims=(0,20))

StatsPlots_grouped_plots

2 Likes