When are round brackets required for VegaLite?

In this example, why are the brackets ( and ) needed to surround the extra @vlplot commands?

using VegaDatasets
dataset("weather.csv") |>
@vlplot(repeat={column=[:temp_max,:precipitation,:wind]}) +
(
    @vlplot() +
    @vlplot(
        :line,
        y={field={repeat=:column},aggregate=:mean,typ=:quantitative},
        x="month(date):o",
        detail="year(date):t",
        color=:location,
        opacity={value=0.2}
    ) +
    @vlplot(
        :line,
        y={field={repeat=:column},aggregate=:mean,typ=:quantitative},
        x="month(date):o",
        color=:location
    )
)

Removing them only plots the last @vlplot so I am guessing that the brackets somehow “keep them together”?

The expression in the () creates a layered spec, and then you want to have that as the spec that gets faceted/repeated. So in general the rule is that if you have a facet/repeat element, you can only add one spec via + as the child spec there.

I’m still not super happy with the rules for this whole composition of plots, I have to admit. They work once one has figured them out, but I’m still wondering whether we could come up with a better story…

Also, I really need to write documentation for that stuff :slight_smile:

Ahh I see, so

@vlplot(repeat={column=[:temp_max,:precipitation,:wind]}) +
(
… anything in here goes in a 'spec' and I can add child vlplots in here
)

Yes, exactly. Inside the parenthesis you can for example create a layered plot, or whatever you want.