I have created a scatter-plot using Vega. My index has a few fields that contain an array of values rather than a single value. for the purpose of simplification, let's assume my index is something like this:
A = {
f1 = 1,
f2 = 10,
f3 = {1,2,3,4,5,6},
f4 = {10,11,12,13,14,15}
}
in which f1, to f4 are field names and the values are as shown above. I have managed to create a scatter-plot using Vega, by assuming f3 as X and f4 as Y and by applying the flatten transform on f3 and f4.
I can color the scatter-plot points based on their f3 or f4 values by creating a scale as:
"scales":[
{
"name": "x",
"domain": {"data": "mydata", "field": "f3"},
"range": "width"
},
{
"name": "y",
"domain": {"data": "mydate", "field": "f4"},
"range": "height"
},
{
"name": "color",
"type": "linear",
"domain": {"data": "mydata", "field": "f3"},
"range": ["#000000", "#FF0000"]
}
]
and then using it in encoding as :
"marks": [
{
"type": "symbol",
"from": {"data":"mydata"},
"encode": {
"update": {
"x": {"scale": "xscale", "field": "f3"},
"y": {"scale": "yscale", "field": "f4"},
"fill": {"scale": "color", "field": "f3"}
}
}
}
]
which works fine, however, I need a method that colors points just based on their array index, e.g. point (f3=1,f4=10)
gets the first color, (f3=2,f4=11)
the second, ..., and (f3=6,f4=15)
gets the last color.
I have tried many many things including creating a signal like this:
"signal":{"name":"order", "value":[1,2,3,4,5,6] }
and then using it in fill like this:
"fill": {"scale": "color", "value": "order"}
or like this:
"fill": {"scale": "color", "value": {"signal":"order"}}
or
"fill": {"scale": "color", "value": {"signal":"order.value"}}
or
"fill": {"signal":"order"}
But none of these worked.
I appreciate if anyone can help.