1

Have this image

enter image description here

Given this vega-lite

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "values": [
      {
        "timestamp": "2011-04-01T17:06:21.000Z",
        "value": 0.44777528325189986
      },
      {
        "timestamp": "2011-04-02T17:06:21.000Z",
        "value": 0.44390285331388984
      },
      {
        "timestamp": "2011-04-03T17:06:21.000Z",
        "value": 0.44813958999449255
      },
      {
        "timestamp": "2011-04-04T17:06:21.000Z",
        "value": 0.4440416510172272
      },
      {
        "timestamp": "2011-04-05T17:06:21.000Z",



        "missing": "NO value KEY HERE!"



      },
      {
        "timestamp": "2011-04-06T17:06:21.000Z",
        "value": 0.3797480270068858
      },
      {
        "timestamp": "2011-04-07T17:06:21.000Z",
        "value": 0.31955288375970203
      },
      {
        "timestamp": "2011-04-08T17:06:21.000Z",
        "value": 0.3171368880067786
      },
      {
        "timestamp": "2011-04-10T17:06:21.000Z",
        "value": 0.30021395605134893
      },
      {
        "timestamp": "2011-04-11T17:06:21.000Z",
        "value": 0.3130485242947531
      }
    ]
  },
  "encoding": {"y": {"field": "timestamp", "type": "temporal", "sort": "ascending"}},
  "layer": [
    {
      "mark": {"type": "line", "interpolate": "cardinal"},
      "encoding": {
        "x": {
          "field": "value",
          "sort": null,
          "type": "quantitative",
          "axis": {"orient": "top"},
          "impute": {"keyvals": ["value"], "method": "mean", "frame": [-5, 5]}
        }
      }
    }
  ]
}

But I thought the impute line would cause it to fill that gap in the data:

"impute": {"keyvals": ["value"], "method": "mean", "frame": [-5, 5]}

Have tried many permutations of this, including:

  1. changing keyvals to ["timestamp"]
  2. Moving the impute line to inside the "encoding": {"y": ... definition
  3. #2 but also switch keyvals to ["value"]

None of those seem to be working

Update

Also tried an impute in transform, and that doesn't work either:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "values": [
      ...
    ]
  },
  "transform": [
    {
      "impute": "value",
      "key": "timestamp",
      "frame": [-1, 1],
      "method": "mean"
    }
  ],
  "encoding": {"y": {"field": "timestamp", "type": "temporal", "sort": "ascending"}},
  "layer": [
    {
      "mark": {"type": "line", "interpolate": "cardinal"},
      "encoding": {
        "x": {
          "field": "value",
          "sort": null,
          "type": "quantitative",
          "axis": {"orient": "top"}
        }
      }
    }
  ]
}

enter image description here

Update 2

Here's something that almost feels like progress, but doesn't behave how I would expect. This is the exact same data with the "transform" : [ "impute" : { ... approach, but now it's displaying imputed_value_value (which by the way is never mentioned in the docs) instead of value:

enter image description here

It does successfully impute, but it imputes (averages) everything, when I only want it to impute places with missing data. Is this how impute is supposed to work?

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "values": [
      ...
    ]
  },
  "transform": [
    {
      "impute": "value",
      "key": "timestamp",
      "frame": [-5, 5],
      "method": "mean"
    }
  ],
  "encoding": {"y": {"field": "timestamp", "type": "temporal", "sort": "ascending"}},
  "layer": [
    {
      "mark": {"type": "line", "interpolate": "cardinal"},
      "encoding": {
        "x": {
          "field": "imputed_value_value",
          "sort": null,
          "type": "quantitative",
          "axis": {"orient": "top"},
        }
      }
    }
  ]
}
Connor
  • 4,216
  • 2
  • 29
  • 40
  • 1
    I've never managed to get impute to work successfully for me. There are a bunch of issues on github around impute and this may fall under one of those so it might be worth raising with the devs there. – Davide Bacci Oct 27 '22 at 09:28

0 Answers0