Skip to content
Vega-Lite templates

Violin / Density

Kernel-density violins for group comparison.

Template previewVega-Lite
Rendering…

Make it your own.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "values": [
      {"g":"x","v":1.2},{"g":"x","v":1.4},{"g":"x","v":1.5},{"g":"x","v":1.7},{"g":"x","v":2.0},{"g":"x","v":2.2},{"g":"x","v":2.5},
      {"g":"y","v":2.0},{"g":"y","v":2.3},{"g":"y","v":2.6},{"g":"y","v":2.8},{"g":"y","v":3.1},{"g":"y","v":3.4},{"g":"y","v":3.7}
    ]
  },
  "transform": [
    {"density":"v","groupby":["g"],"extent":[0,5]}
  ],
  "mark": {"type":"area","orient":"horizontal"},
  "encoding": {
    "y": {"field":"value","type":"quantitative","title":"v"},
    "x": {"field":"density","type":"quantitative","stack":"center","title":null,"axis": null},
    "color": {"field":"g","type":"nominal"},
    "column": {"field":"g","type":"nominal","header":{"labelOrient":"bottom","title": null}}
  },
  "width": 80, "height": 260
}