Hello, I want to reproduce an analysis like that.
I want to reproduce an analysis with the vega or vega-lite kibana plugin. I would like to associate the total of the sites each day. Here is my vega code. If possible associate an interactive legend with a multiple selection.
Here is the code I want to transform
##############################################################
{
"$schema": "https://vega.github.io/schema/vega/v4.json",
"width": 300,
"height": 240,
"padding": 5,
"data": [
{
"name": "table",
"values": [
{"jour":"A", "site":0, "nb_passage":0.1},
{"jour":"A", "site":1, "nb_passage":0.6},
{"jour":"A", "site":2, "nb_passage":0.9},
{"jour":"A", "site":3, "nb_passage":0.4},
{"jour":"B", "site":0, "nb_passage":0.7},
{"jour":"B", "site":1, "nb_passage":0.2},
{"jour":"B", "site":2, "nb_passage":1.1},
{"jour":"B", "site":3, "nb_passage":0.8},
{"jour":"C", "site":0, "nb_passage":0.6},
{"jour":"C", "site":1, "nb_passage":0.1},
{"jour":"C", "site":2, "nb_passage":0.2},
{"jour":"C", "site":3, "nb_passage":0.7}
],
"transform": [
{ "type": "joinaggregate",
"fields": [ "np_passage"],
"ops": [ "sum"],
"as": [ "m"]
},
{"type":"formula", "expr": "datum.nb_passage", "as":"nb_passage"},
{"type":"formula", "expr": "datum.jour", "as": "jour"}
]
}
],
"scales": [
{
"name": "xscale",
"type": "band",
"domain": {"data": "table", "field": "jour"},
"range": "width",
"padding": 0.2
},
{
"name": "yscale",
"type": "linear",
"domain": {"data": "table", "field": "nb_passage"},
"range": "height",
"round": true,
"zero": true,
"nice": true
},
{
"name": "color",
"type": "ordinal",
"domain": {"data": "table", "field": "site"},
"range": {"scheme": "category20"}
}
],
"axes": [
{"orient": "left", "scale": "yscale", "tickSize": 6, "labelPadding": 4, "zindex": 1},
{"orient": "bottom", "scale": "xscale"}
],
"marks": [
{
"type": "group",
"clip": true,
"foreground" : false,
"from": {
"facet": {
"data": "table",
"name": "facet",
"groupby": ["jour"]
}
},
"encode": {
"enter": {
"x": {"scale": "xscale", "field": "jour"}
}
},
"signals": [
{"name": "width", "update": "bandwidth('xscale')"}
],
"scales": [
{
"name": "pos",
"type": "band",
"range": "width",
"domain": {"data": "facet", "field": "site"}
}
],
"marks": [
{
"name": "bars",
"from": {"data": "facet"},
"type": "rect",
"encode": {
"enter": {
"x": {"scale": "pos", "field": "site"},
"width": {"scale": "pos", "band": 1},
"y": {"scale": "yscale", "field": "nb_passage"},
"y2": {"scale": "yscale", "value": 0},
"fill": {"scale": "color", "field": "site"}
}
}
},
{
"type": "text",
"from": {"data": "bars"},
"encode": {
"enter": {
"y": {"field": "y", "offset": -4},
"x": {"field": "x", "offset": {"field": "width", "mult": 0.3}},
"fill": [
{"value": "black"}
],
"align": {"value": "left"},
"baseline": {"value": "middle"},
"text": {"field": "datum.nb_passage"},
"angle":{"value": -55},
"fontSize": {"value": 10}
}
}
}
]
}
]
}
Thank you