question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Don't show legend for size with scale.zero = true?

See original GitHub issue

Vega-Lite outputs always have zero: true for scale of size to ensure correct scaling.

However, when zero is true, Vega legend always include 0, which looks kinda weird.

For example, in this VG spec from the following VL spec:

{
  "description": "A simple bar chart with embedded data.",
  "data": {
    "values": [
      {"a": "A","b": 10},
      {"a": "B","b": 20},
      {"a": "C","b": 30},
      {"a": "D","b": 40}
    ]
  },
  "mark": "circle",
  "encoding": {
    "x": {"field": "a", "type": "ordinal"},
    "size": {"field": "b", "type": "quantitative", "scale": {"zero": true, "range": [0, 361]}}
  }
}

vega_editor

The field b spans [10,40], but the legend include 0, which is unnecessary.

It’d be great if 0 is excluded.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jheercommented, Jan 18, 2017

Right now I’m experimenting with the following and so far it seems to work well: Remove a zero-sized entry if and only if (1) there is an active size encoding driving the legend, (2) the removed value is the first entry in the legend, and (3) the removed value was generated from the scale domain, not supplied as part of an explicit values array. Sound good?

(Note that our legend entry generator has access to the backing scales, but not their Vega specs, so we don’t know if zero: true is set or not.)

0reactions
jheercommented, Jan 21, 2017

Suppression of initial zero-sized legend entries was included in the v3.0.0-beta.15 release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hide legend elements that have value zero in ggplot
I am using the "turbo" color scale from Viridis because I need a very wide coverage of colors to be able to distinguish...
Read more >
Legend guide — guide_legend • ggplot2
Legend type guide shows key (i.e., geoms) mapped onto values. Legend guides for various scales are integrated if possible.
Read more >
Controlling legend appearance in ggplot2 with override.aes
Changing the legend appearance without changing the plot appearance can be done using the override.aes argument in guide_legend().
Read more >
Legend | Vega-Lite
Similar to axes, legends visualize scales. ... If set to true (default) or "parity" , a strategy of removing every other label is...
Read more >
15 Scales and guides | ggplot2
A legend can display multiple aesthetics (e.g. colour and shape), from multiple layers (Section 15.7. · Axes always appear in the same place....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found