2

I have a vegalite plot that looks like this. There are 3 operating systems (see legend) and i'm plotting a rater for every version. I would like to 'nudge'/jitter the x values for the 3 OSs for a given version on the y-axis so they are not in one line. In R's lattice, this would be 'jittering'. Is there a way to modify the vegalite spec to do this? I'm using R's vegawidget and creating the spec myself.

Thanks much

Sapsi
  • 711
  • 5
  • 16

1 Answers1

1

Jitter or offset encodings are not yet implemented in Vega-Lite; see https://github.com/vega/vega-lite/issues/4703 for the relevant feature request.

In the meantime, the best way to approximate what you want is to use a column encoding, along with an x encoding built from a randomly-generated jitter. The transform and encoding might look something like this:

  "transform": [{"calculate": "random()", "as": "jitter"}],
  "encoding": {
    "size": {"value": 65},
    "column": {"field": "cv", "type": "ordinal", "spacing": 0},
    "x": {
      "field": "jitter",
      "type": "quantitative",
      "axis": {"title": null, "labels": false},
      "scale": {"domain": [-1, 2]}
    },
    "y": {"field": "c", "type": "quantitative"},
    "color": {"field": "os", "type": "nominal"}
  }

A simplified example using your data can be seen here: enter image description here

From there you can customize grids, ticks, labels, and the rest to get it to look how you would like. It's imperfect, but it's the only way to currently get this kind of behavior within the Vega-Lite grammar.

jakevdp
  • 77,104
  • 11
  • 125
  • 160