Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenating multiple data sources in Vega

Tags:

vega

In Vega, I have multiple data sources, and sometimes I want to merge them together one after another. For example, given sources A, B, and C, with two columns - date and value, I might want to create a combined data source with columns date, value, source, where the last column's values will be A, B, or C. Lookup transformation does not seem to be working for this because dates are not necessarily matching. Thanks!

like image 731
Yuri Astrakhan Avatar asked Oct 31 '25 17:10

Yuri Astrakhan


2 Answers

As of Vega 3, it is possible to concatenate multiple data sources using source field in the data section:

 "source": ["source1", "source2", ...]`

The feature was added in v3.0.0-rc7.

like image 58
Yuri Astrakhan Avatar answered Nov 03 '25 06:11

Yuri Astrakhan


I don't think it's possible to merge multiple datasets within Vega [version 2 only, it is possible in v3 -- added by @yurik], unfortunately. Adding a new field (column) to an existing dataset is straightforward: use the formula transform. I'm stuck for an answer to the merge question, though.

Did you ask the merge question out of interest or out of necessity? If the latter, then you could merge the datasets outside Vega -- using d3, for example -- and then pass the new dataset at runtime.

like image 39
Iain Dillingham Avatar answered Nov 03 '25 06:11

Iain Dillingham