Skip to content

Unable to combine legends when using line mark with "point": true or separate line and point layers #9748

Open

Description

@labkey-alan

Bug Description

Repro for the bug can be found on this vega editor url.

My spec, minus the data, looks like:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v6.json",
  "data": {
    "values": []
  },
  "mark": {"type": "line", "point": true},
  "encoding": {
    "x": {
      "field": "maxSpeed.value",
      "type": "quantitative",
      "title": "Max Speed"
    },
    "y": {
      "field": "weight.value",
      "type": "quantitative",
      "title": "Weight"
    },
    "color": {
      "field": "type.value",
      "type": "nominal",
      "title": "Type",
      "legend": {"title": "Type", "type": "symbol"}
    },
    "shape": {
      "field": "type.value",
      "type": "nominal",
      "title": "Type",
      "legend": {"title": "Type"}
    }
  }
}

With the above spec I would expect the legend to have one section "Type" and to include one legend value per type, with the color and shape represented per value on the legend:

Image

However, what I get are two distinct legends, one for the shape, and one for the color. If I change the mark to use point like so:

"mark": { "type": "point" },

I get a properly combined legend:

Image

Checklist

  • I checked for duplicate issues.

Activity

  1. labkey-alan commented on Jan 9, 2026

    @labkey-alan
    Author

    Here is another visualization that I created that shows the same problem, but with a slightly different Vega-Lite spec. Here is the spec without the data (the link to the Vega Editor includes the data):

    {
      "$schema": "https://vega.github.io/schema/vega-lite/v6.json",
      "data": {
        "values": []
      },
      "layer": [
        {
          "mark": {"type": "line", "point": false},
          "encoding": {
            "color": {"field": "type.value", "type": "nominal", "title": "Type"}
          }
        },
        {
          "mark": {"type": "point", "opacity": 1, "filled": true, "size": 55},
          "encoding": {
            "color": {"field": "type.value", "type": "nominal", "title": "Type"},
            "shape": {"field": "type.value", "type": "nominal", "title": "Type"}
          }
        }
      ],
      "encoding": {
        "x": {
          "field": "maxSpeed.value",
          "type": "quantitative",
          "title": "Max Speed"
        },
        "y": {"field": "weight.value", "type": "quantitative", "title": "Weight"}
      }
    }

    So, instead of trying to use just the line mark with "point": true I went ahead and created two individual layers, one for the lines, one for the points. Each layer defines their own color encoding, and the point layer includes an encoding for shape. I would expect this to result in a combined legend, but it does not. The results are basically identical to using only the line mark with "point": true. I tried disabling the legend for the line layer but that just drops the color values from the legend.

    Image
  2. changed the title [-]Using mark type line with point: true does not combine legends[/-] [+]Unable to combine legends when using line mark with "point": true or separate line and point layers[/+] on Jan 9, 2026
  3. ByzantineFailure commented on Mar 19, 2026

    @ByzantineFailure

    Noting that we encounter this issue as well when attempting to use a shape mark to apply symbols to different series in a stacked bar chart for accessibility purposes (need a non-color way to differentiate them).

    {
      "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
      "description": "A simple bar chart with embedded data and shapes in the center",
      "data": {
        "values": [...],
      },
      "transform": [
        {
          "stack": "b",
          "groupby": ["a"],
          "as": ["y0", "y1"]
        },
        {"calculate": "(datum.y0 + datum.y1) / 2", "as": "midpoint"}
      ],
      "encoding": {
        "x": {"field": "a", "title": "Category", "type": "nominal", "axis": {"labelAngle": 0}},
        "color": {
          "field": "c",
          "title": "Product",
          "type": "nominal",
          "scale": {"scheme": "category20"}
        },
        "shape": {
          "field": "c",
          "type": "nominal"
        }
      },
      "layer": [
        {
          "mark": {"type": "bar"},
          "encoding": {
            "y": {"field": "y0", "type": "quantitative", "title": "Value" },
            "y2": {"field": "y1", "title": "Value", "type": "quantitative"},
          }
        },
        {
          "mark": {"type": "point", "filled": true, "stroke": "black", "size": 100},
          "encoding": {
            "y": {"field": "midpoint", "type": "quantitative"},
          }
        }
      ]
    }
    
    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions