Search code examples
powerbivisualizationvega-litedeneb

Is there a Vega-lite equivalent to the scale_y_continuous function?


I have a graph visualized in R that I'd like to create in PowerBI using Deneeb. In R there's the function "scale_y_log10". Is there a way do the same thing in Vega-lite?

I've used the basic "scale": "type:"log", but I'd like to do more.


Solution

  • You need to ensure the values in your combined axis do not contain negative numbers on a log scale.

    {
      "data": {"name": "dataset"},
      "transform": [
        {
          "filter": "datum['virus'] !== null"
        },
        {"filter": "datum['virus'] !== 0"}
      ],
      "encoding": {
        "x": {
          "field": "date",
          "title": "Date",
          "type": "temporal"
        },
        "y": {
          "field": "virus",
          "title": "(Normalized Levels (N1/PMMOV Concentrations)",
          "type": "quantitative",
          "scale": {"type": "log"}
        }
      },
      "layer": [
        {
          "mark": {
            "type": "point",
            "tooltip": true,
            "filled": true
          }
        },
        {
          "mark": {
            "type": "line",
            "color": "black"
          },
          "transform": [
            {
              "filter": "datum['virus'] != null"
            },
            {
              "filter": "datum['virus'] != 0"
            },
            {
              "loess": "virus",
              "on": "date",
              "as": ["a", "b"],
              "bandwidth": 0.3
            },
            {"filter": "datum['b'] >1"}
          ],
          "encoding": {
            "x": {"field": "a"},
            "y": {"field": "b"}
          }
        }
      ]
    }