With a wide dataframe and vectors you’d have to conditionally place or not place elements in these vectors to “toggle” them. I find that Julia doesn’t make this particularly pretty, you can either push! or vcat conditionally or you can splat empty vectors like ["A", (condition ? ["B"], [])...].
But you can do the two-layer approach you were trying, to make the color correct you just cannot use dims in that case. Instead, each layer needs its own categorical color value. But the direct helper makes this easier because you don’t have to add columns just for those categorical values. The code then becomes:
df = let
t = range(0, 9, length = 1000)
mass_lab_frame = @. cos(t)^2
mass_col_frame = @. sin(t)^2
(; t, mass_lab_frame, mass_col_frame)
end
mappings = mapping(:t, :mass_lab_frame => "observed mass", color = direct("Lab frame"))
if true
mappings += mapping(:t, :mass_col_frame => "observed mass", color = direct("Collider frame"))
end
data(df) * mappings * visual(Lines) |> draw
And with if false:
The repetition that remains is :t and => "observed mass" but I don’t see a quick way around that right now, other than storing "observed mass" in a variable and pairing that.

