For complex interactions: define a named selection that can be referenced by marks and scales. This is how you build linked views, conditional encoding, and interactive legends.
Examples
# Interactive legend: click legend entries to filter
glyph(mtcars, x = wt, y = mpg) |>
mark_point(color = cyl) |>
selection("legend_filter", type = "legend", fields = "cyl")
#> <glyph_spec: 32 x 11, 1 mark(s)>