Search code examples
vega-lite

force a legend when there is no corresponding data


I'm hoping to get pointers for how to include an item in the legend despite the fact that it's not in the data---I tried to add it by way of sort, but that doesn't appear to work---editor link. In this example, I want "Not helpful" to show up in the legend, despite the fact that it was not present in any responses.

I understand that this is somewhat against the whole visual encodings concept, but I think the use case is valid.

Thanks for the help!


Solution

  • You can do this by specifying the scale domain:

    "scale": {
      "domain": [
        "Extremely helpful",
        "Very helpful",
        "Somewhat helpful",
        "Not so helpful",
        "Not helpful"
      ]
    }
    

    The result looks like this (view in editor): enter image description here