I've been trying for the last few days to rename the legend labels on my vega-lite chart.
Normally these labels match their respective data field names. I have a case where I'd like to give them a more descriptive name, but without renaming the original data names.
A simplified example:
vl.markLine()
.data([
{ t:1, v:5, c:'a' }, { t:2, v:3, c:'a' }, { t:3, v:7, c:'a' },
{ t:1, v:6, c:'b' }, { t:2, v:8, c:'b' }, { t:3, v:2, c:'b' }
])
.encode(
vl.x().fieldQ('t'),
vl.y().fieldQ('v'),
vl.color().fieldN('c')
)
.render()
How can I rename 'a' and 'b' in the legend, without changing the original data?
(I'm using the javascript API but will be happy with a JSON solution too).
I'd like to find a way that doesn't involve just copying and mapping all the data to another variable name just for the sake of the legend labels.
I've yet to find a way of manually entering the legend labels as something like "labels": ['long name for a', 'long name for b'].
