vega / vega-lite

A concise grammar of interactive graphics, built on Vega.
https://vega.github.io/vega-lite/
BSD 3-Clause "New" or "Revised" License
4.65k stars 606 forks source link

Viz distorted on attempting symlog #6640

Open pramitchoudhary opened 4 years ago

pramitchoudhary commented 4 years ago

I have a use-case where I need to bin the values outside of vega-lite but I still need to set symlog scale for the X axis.

In doing so, the ticks on the X-axis seem to get distorted. Mentioned below is the viz schema and the generated viz. Any help is much appreciated.

Screenshot 2020-06-17 18 14 36
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "width": 800,
  "height": 50,
  "data": {
    "values": [
      {
        "category": "Movies",
        "bin_start": -358.05252,
        "bin_end": 23072.9496968421,
        "n_samples": 9303,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 23072.9496968421,
        "bin_end": 46503.9519136842,
        "n_samples": 857,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 46503.9519136842,
        "bin_end": 69934.9541305263,
        "n_samples": 267,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 69934.9541305263,
        "bin_end": 93365.9563473684,
        "n_samples": 245,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 93365.9563473684,
        "bin_end": 116796.9585642105,
        "n_samples": 118,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 116796.9585642105,
        "bin_end": 140227.9607810527,
        "n_samples": 91,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 140227.9607810527,
        "bin_end": 163658.9629978948,
        "n_samples": 33,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 163658.9629978948,
        "bin_end": 187089.9652147369,
        "n_samples": 56,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 187089.9652147369,
        "bin_end": 210520.967431579,
        "n_samples": 74,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 210520.967431579,
        "bin_end": 233951.9696484211,
        "n_samples": 94,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 233951.9696484211,
        "bin_end": 257382.9718652632,
        "n_samples": 84,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 257382.9718652632,
        "bin_end": 280813.9740821053,
        "n_samples": 66,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 280813.9740821053,
        "bin_end": 304244.9762989474,
        "n_samples": 51,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 304244.9762989474,
        "bin_end": 327675.9785157895,
        "n_samples": 54,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 327675.9785157895,
        "bin_end": 351106.9807326316,
        "n_samples": 53,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 351106.9807326316,
        "bin_end": 374537.9829494737,
        "n_samples": 43,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 374537.9829494737,
        "bin_end": 397968.9851663157,
        "n_samples": 32,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 397968.9851663157,
        "bin_end": 421399.9873831578,
        "n_samples": 31,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Movies",
        "bin_start": 421399.9873831578,
        "bin_end": 444830.9895999999,
        "n_samples": 5,
        "Product Categories": "Movies",
        "std_dev": 66132.1895549581,
        "skewness": 3.6754766772,
        "kurtosis": 16.7360238675
      },
      {
        "category": "Beauty",
        "bin_start": -358.05252,
        "bin_end": 23072.9496968421,
        "n_samples": 3688,
        "Product Categories": "Beauty",
        "std_dev": 891.3476191094,
        "skewness": 2.478938978,
        "kurtosis": 8.3494984242
      },
      {
        "category": "Grocery",
        "bin_start": -358.05252,
        "bin_end": 23072.9496968421,
        "n_samples": 1135,
        "Product Categories": "Grocery",
        "std_dev": 74.8198784916,
        "skewness": 5.0288177412,
        "kurtosis": 37.2897729632
      },
      {
        "category": "Per Supplies",
        "bin_start": -358.05252,
        "bin_end": 23072.9496968421,
        "n_samples": 952,
        "Product Categories": "Per Supplies",
        "std_dev": 160.4107246916,
        "skewness": 6.7431927664,
        "kurtosis": 69.6395623691
      },
      {
        "category": "Clothing",
        "bin_start": -358.05252,
        "bin_end": 23072.9496968421,
        "n_samples": 8781,
        "Product Categories": "Clothing",
        "std_dev": 28249.3390636409,
        "skewness": 3.4800921119,
        "kurtosis": 16.6750939155
      },
      {
        "category": "Clothing",
        "bin_start": 23072.9496968421,
        "bin_end": 46503.9519136842,
        "n_samples": 794,
        "Product Categories": "Clothing",
        "std_dev": 28249.3390636409,
        "skewness": 3.4800921119,
        "kurtosis": 16.6750939155
      },
      {
        "category": "Clothing",
        "bin_start": 46503.9519136842,
        "bin_end": 69934.9541305263,
        "n_samples": 416,
        "Product Categories": "Clothing",
        "std_dev": 28249.3390636409,
        "skewness": 3.4800921119,
        "kurtosis": 16.6750939155
      },
      {
        "category": "Clothing",
        "bin_start": 69934.9541305263,
        "bin_end": 93365.9563473684,
        "n_samples": 223,
        "Product Categories": "Clothing",
        "std_dev": 28249.3390636409,
        "skewness": 3.4800921119,
        "kurtosis": 16.6750939155
      },
      {
        "category": "Clothing",
        "bin_start": 93365.9563473684,
        "bin_end": 116796.9585642105,
        "n_samples": 56,
        "Product Categories": "Clothing",
        "std_dev": 28249.3390636409,
        "skewness": 3.4800921119,
        "kurtosis": 16.6750939155
      },
      {
        "category": "Clothing",
        "bin_start": 116796.9585642105,
        "bin_end": 140227.9607810527,
        "n_samples": 72,
        "Product Categories": "Clothing",
        "std_dev": 28249.3390636409,
        "skewness": 3.4800921119,
        "kurtosis": 16.6750939155
      },
      {
        "category": "Clothing",
        "bin_start": 140227.9607810527,
        "bin_end": 163658.9629978948,
        "n_samples": 93,
        "Product Categories": "Clothing",
        "std_dev": 28249.3390636409,
        "skewness": 3.4800921119,
        "kurtosis": 16.6750939155
      },
      {
        "category": "Clothing",
        "bin_start": 163658.9629978948,
        "bin_end": 187089.9652147369,
        "n_samples": 62,
        "Product Categories": "Clothing",
        "std_dev": 28249.3390636409,
        "skewness": 3.4800921119,
        "kurtosis": 16.6750939155
      },
      {
        "category": "Clothing",
        "bin_start": 187089.9652147369,
        "bin_end": 210520.967431579,
        "n_samples": 16,
        "Product Categories": "Clothing",
        "std_dev": 28249.3390636409,
        "skewness": 3.4800921119,
        "kurtosis": 16.6750939155
      },
      {
        "category": "Crafts",
        "bin_start": -358.05252,
        "bin_end": 23072.9496968421,
        "n_samples": 1550,
        "Product Categories": "Crafts",
        "std_dev": 211.2122576613,
        "skewness": 6.2880694149,
        "kurtosis": 75.5068446462
      },
      {
        "category": "Subscription",
        "bin_start": -358.05252,
        "bin_end": 23072.9496968421,
        "n_samples": 6856,
        "Product Categories": "Subscription",
        "std_dev": 124.2458878437,
        "skewness": 21.3400908743,
        "kurtosis": 700.2046613775
      },
      {
        "category": "Home Services",
        "bin_start": -358.05252,
        "bin_end": 23072.9496968421,
        "n_samples": 10632,
        "Product Categories": "Home Services",
        "std_dev": 1784.6548728473,
        "skewness": 3.4069180991,
        "kurtosis": 16.5568120317
      },
      {
        "category": "Software",
        "bin_start": -358.05252,
        "bin_end": 23072.9496968421,
        "n_samples": 5511,
        "Product Categories": "Software",
        "std_dev": 1244.1843664504,
        "skewness": 3.6064407118,
        "kurtosis": 17.7142196324
      },
      {
        "category": "Electronics",
        "bin_start": -358.05252,
        "bin_end": 23072.9496968421,
        "n_samples": 3599,
        "Product Categories": "Electronics",
        "std_dev": 1335.3446694169,
        "skewness": 8.29380839,
        "kurtosis": 78.1417945128
      },
      {
        "category": "Collectibles",
        "bin_start": -358.05252,
        "bin_end": 23072.9496968421,
        "n_samples": 1372,
        "Product Categories": "Collectibles",
        "std_dev": 254.8348640702,
        "skewness": 3.3796948374,
        "kurtosis": 26.003708473
      }
    ]
  },
  "config": {
    "axis": {"labelFontStyle": "sans-serif"},
    "facet": {"spacing": 5},
    "view": {"stroke": "transparent"}
  },
  "bounds": "flush",
  "mark": {
    "type": "area",
    "tooltip": true,
    "fillOpacity": 0.5,
    "strokeOpacity": 0.8,
    "strokeWidth": 1,
    "interpolate": "monotone"
  },
  "selection": {"grid": {"type": "interval", "bind": "scales"}},
  "encoding": {
    "tooltip": [
      {"field": "category", "type": "nominal"},
      {"field": "bin_start", "type": "quantitative"},
      {"field": "bin_end", "type": "quantitative"},
      {"field": "n_samples", "type": "quantitative"},
      {"field": "skewness", "type": "quantitative"},
      {"field": "kurtosis", "type": "quantitative"},
      {"field": "std_dev", "type": "quantitative"},
      {"field": "tail_type", "type": "nominal"}
    ],
    "x": {
      "field": "bin_start",
      "bin": {"binned": true,  "maxbins": 10},
      "type": "quantitative",
      "axis": {"title": "Revenue (log)"},
      "scale": {"type": "symlog"}
    },
    "y": {
      "field": "n_samples",
      "type": "quantitative",
      "axis": {
        "title": null,
        "grid": false,
        "labels": true,
        "domain": false,
        "ticks": false
      }
    },
    "color": {"field": "category", "type": "nominal", "legend": null},
    "row": {
      "field": "category",
      "type": "nominal",
      "header": {
        "title": "Product Categories",
        "labelAngle": 0,
        "labelAlign": "left",
        "labelOrient": "left",
        "labelAnchor": "middle",
        "labelLimit": 100,
        "labelPadding": 50
      },
      "sort": [
        "Grocery",
        "Arts",
        "Per Supplies",
        "Toys",
        "Collectibles",
        "Sports",
        "Crafts",
        "School Supplies",
        "Music",
        "Beauty",
        "Subscription",
        "Software",
        "Automotive",
        "Business",
        "Home Services",
        "Electronics",
        "Tools",
        "Games",
        "Financial Services",
        "Computers",
        "Outdoors",
        "Clothing",
        "Industrial",
        "Health",
        "Baby Products",
        "Books",
        "Digital",
        "Office Supplies",
        "Movies"
      ]
    }
  },
  "resolve": {"scale": {"x": "shared", "y": "independent"}}
}
domoritz commented 4 years ago

Can you try to create a minimal example that shows the problem?

pramitchoudhary commented 4 years ago

@domoritz Sure, do you mean reduce the size of the .json schema mentioned above?

domoritz commented 4 years ago

Yeah, a minimal (ideally there does not exist a smaller) spec.