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.

Small non-zero values for size scale are not visible

See original GitHub issue

In Vega-Lite 2.x, if you encode a quantity with size and that quantity has elements with value zero, those points do not appear on the plot with the default scale:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
  "data": {
    "url": "https://vega.github.io/vega-datasets/data/seattle-weather.csv"
  },
  "encoding": {
    "color": {
      "field": "weather",
      "type": "nominal"
    },
    "size": {
      "field": "precipitation",
      "type": "quantitative"
    },
    "x": {
      "field": "temp_min",
      "type": "quantitative"
    },
    "y": {
      "field": "temp_max",
      "type": "quantitative"
    }
  },
  "mark": "point"
}

vega

In Vega-Lite 1.x, this was not the case; here’s the result of the above spec with VL1:

vega 2

In VL2, you can fix this by setting the size scale domain to start at a negative number:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
  "data": {
    "url": "https://vega.github.io/vega-datasets/data/seattle-weather.csv"
  },
  "encoding": {
    "color": {
      "field": "weather",
      "type": "nominal"
    },
    "size": {
      "field": "precipitation",
      "type": "quantitative",
      "scale": {"domain": [-1, 50]}
    },
    "x": {
      "field": "temp_min",
      "type": "quantitative"
    },
    "y": {
      "field": "temp_max",
      "type": "quantitative"
    }
  },
  "mark": "point"
}

vega 1

I think that silently hiding valid data should be considered a bug, and that the domain should default to something like what is in the final panel.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
domoritzcommented, Apr 22, 2018

Something like

{
  "$schema": "https://vega.github.io/schema/vega/v3.0.json",
  "autosize": "pad",
  "padding": 5,
  "width": 500,
  "height": 500,
  "style": "cell",
  "data": [
    {
      "name": "source_0",
      "url": "https://vega.github.io/vega-datasets/data/seattle-weather.csv",
      "format": {
        "type": "csv",
        "parse": {
          "precipitation": "number",
          "temp_min": "number",
          "temp_max": "number"
        },
        "delimiter": ","
      },
      "transform": [
        {
          "type": "filter",
          "expr": "datum[\"precipitation\"] !== null && !isNaN(datum[\"precipitation\"]) && datum[\"temp_min\"] !== null && !isNaN(datum[\"temp_min\"]) && datum[\"temp_max\"] !== null && !isNaN(datum[\"temp_max\"])"
        }
      ]
    }
  ],
  "marks": [
    {
      "name": "marks",
      "type": "symbol",
      "style": ["point"],
      "from": {"data": "source_0"},
      "encode": {
        "update": {
          "opacity": {"value": 0.7},
          "fill": {
            "signal": "scale('size', datum.precipitation) < 1 ? scale('color', datum.weather) : 'transparent'"
          },
          "stroke": {"scale": "color", "field": "weather"},
          "x": {"scale": "x", "field": "temp_min"},
          "y": {"scale": "y", "field": "temp_max"},
          "size": {
            "signal": "scale('size', datum.precipitation) < 1 ? 1 : scale('size', datum.precipitation)"
          }
        }
      }
    }
  ],
  "scales": [
    {
      "name": "x",
      "type": "linear",
      "domain": {"data": "source_0", "field": "temp_min"},
      "range": [0, {"signal": "width"}],
      "nice": true,
      "zero": true
    },
    {
      "name": "y",
      "type": "linear",
      "domain": {"data": "source_0", "field": "temp_max"},
      "range": [{"signal": "height"}, 0],
      "nice": true,
      "zero": true
    },
    {
      "name": "color",
      "type": "ordinal",
      "domain": {"data": "source_0", "field": "weather", "sort": true},
      "range": "category"
    },
    {
      "name": "size",
      "type": "linear",
      "domain": {"data": "source_0", "field": "precipitation"},
      "range": [0.1, 361],
      "nice": false,
      "zero": true
    }
  ],
  "axes": [
    {
      "scale": "x",
      "orient": "bottom",
      "title": "temp_min",
      "labelFlush": true,
      "labelOverlap": true,
      "tickCount": {"signal": "ceil(width/40)"},
      "zindex": 1
    },
    {
      "scale": "x",
      "orient": "bottom",
      "grid": true,
      "tickCount": {"signal": "ceil(width/40)"},
      "gridScale": "y",
      "domain": false,
      "labels": false,
      "maxExtent": 0,
      "minExtent": 0,
      "ticks": false,
      "zindex": 0
    },
    {
      "scale": "y",
      "orient": "left",
      "title": "temp_max",
      "labelOverlap": true,
      "tickCount": {"signal": "ceil(height/40)"},
      "zindex": 1
    },
    {
      "scale": "y",
      "orient": "left",
      "grid": true,
      "tickCount": {"signal": "ceil(height/40)"},
      "gridScale": "x",
      "domain": false,
      "labels": false,
      "maxExtent": 0,
      "minExtent": 0,
      "ticks": false,
      "zindex": 0
    }
  ],
  "legends": [
    {
      "stroke": "color",
      "title": "weather",
      "encode": {"symbols": {"update": {"opacity": {"value": 0.7}}}}
    },
    {
      "size": "size",
      "title": "precipitation",
      "encode": {"symbols": {"update": {"opacity": {"value": 0.7}}}}
    }
  ],
  "config": {"axisY": {"minExtent": 30}}
}

image

1reaction
kanitwcommented, Apr 22, 2018

I wonder whether there is a way to get filled circles of radius 1 for the smallest circles instead of hollow circles.

Yes, you can add production rule, instead of making scale inaccurate.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to suppress 0 values in an Excel chart - TechRepublic
Uncheck the Show a zero in cells that have zero value option (as shown in Figure C). Click OK.
Read more >
Text displays too large in paper space in AutoCAD
Issue: Text objects in an AutoCAD drawing are blown up or scaled much larger than expected when displayed in a layout, in a...
Read more >
Measurements and Error Analysis - WebAssign
Failure to zero a device will result in a constant error that is more significant for smaller measured values than for larger ones....
Read more >
Using Effect Size—or Why the P Value Is Not Enough - NCBI
In this paper, we target readers with little or no statistical background in ... different scales so no direct comparison is possible; or...
Read more >
Surpress Zero values in Charts - Microsoft Power BI Community
Thanks guys. I tried the "show item with no data" but didn't work. I think it is because there are data but the...
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