Is there a way to change scale type (linear/log) dynamically?

29 Views Asked by At

I'd like to be able to use a parameter for "scale": {"type": "linear/log"} but the documentation says only strings are allowed and i can't find a way to use a param/expression/variable.

Does anyone know a way around this?

Cheers.

Here i'd like to be able to use scaleTypeX in place of "linear" or "log"

{
  "data": {"name": "dataset"},
  "params":[
    {
      "name":"scaleTypeX",
      "value": "log"
    }  
  ],
  "layer": [
    {    
      "mark": {
        "type": "line",
        "tooltip": true
      },
        "encoding": {
          "x": {
            "field": "RANKPercentileMeasure_1",
            "type": "quantitative",
            "scale":{
              "zero": false,
              "type": "linear"
            },
            "axis":{
              "labelSeparation":250
            }
          },
          "y": {
            "field": "RANKPercentileMeasure_2",
            "type": "quantitative",
            "scale":{
              "zero": false,
              "type": "log",
              "base": 0
            }
            
          }
        }
    }
  ]  
}
1

There are 1 best solutions below

0
APB Reports On

Try something like this:

_regression_method value should be either log or linear.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "description": "Google's stock price over time.",
  "data": {"url": "data/stocks.csv"},
  "params": [{"name": "_regression_method", "value": "log"}],
  "transform": [{"filter": "datum.symbol==='AAPL'"}],
  "layer": [
    {
      "mark": {"type": "line", "color": "silver"},
      "encoding": {
        "x": {"field": "date", "type": "temporal"},
        "y": {"field": "price", "type": "quantitative"}
      }
    },
    {
      "name": "REGRESSION_LINE",
      "transform": [
        {
          "regression": "price",
          "on": "date",
          "method": {"signal": "_regression_method"}
        }
      ],
      "mark": {"type": "line", "color": "#D64550"},
      "encoding": {
        "x": {"field": "date", "type": "temporal"},
        "y": {"field": "price", "type": "quantitative"}
      }
    }
  ]
}