vegalite icon indicating copy to clipboard operation
vegalite copied to clipboard

support of "layers" specification (multiple marks in one chart)

Open TomBor opened this issue 8 years ago • 6 comments

It would be really great to have "layers" in vegalite as this example on stackoverflow show it. Thanks

TomBor avatar Jan 24 '17 09:01 TomBor

I'm not seeing great specs on Vega-Lite for layer... if we knew what are the required and allowed fields it shouldn't be too bad to implement.

Do you have any ideas for the API? That's a far more difficult question IMO.

jsonbecker avatar Jan 24 '17 15:01 jsonbecker

layers works in vega-editor, so I suppose it's not specific to future 2.0. But I can't find any specs for layers except in this pull request. I don't know if it help you.

TomBor avatar Jan 25 '17 16:01 TomBor

It looks like layers are an array of mark and encoding pairs. If so, maybe the right way to do this would be something like:

vegalite() %>%
add_data(...) %>%
add_layer(mark = mark_bar(), encoding = list(encode_x(), encode_y())) %>%
add_layer(mark = mark_point(), encoding = list(...)) %>%
...

I'm a little worried without more docs that it would be easy to make invalid JSON out of this, but I could see it being possible. Note, I'd probably have add_layer pack any existing mark and encoding elements into a layer...

jsonbecker avatar Jan 25 '17 19:01 jsonbecker

Another thought:

You could add a layer property that defaults to 1 for each property that can be in a layer. Then you can have add_layer() append to the layer list, layer_count() tell you how many layers an object has, show_layers() reply with the list saved to layer. Then, to_spec, print, etc that evaluates it can have a check for layer_count() == 1 and basically remove the layer list in that case and unnest it.

That'd be a pretty big change though.

jsonbecker avatar Jan 26 '17 01:01 jsonbecker

https://idl.cs.washington.edu/files/2017-VegaLite-InfoVis.pdf - 3.2 View Composition Algebra Describes layers, hconcat/vconcat, and facet but I don't see these descriptions on the Vega-Lite site, other than faceting through row or column channels.

kenklin avatar Mar 29 '17 21:03 kenklin

Vega-lite 2.0 documentation is on line but not complete. Specifications for layers will be here : https://vega.github.io/vega-lite/docs/layer.html

  • Slides from OpenVizConf : https://www.domoritz.de/talks/VegaLite-OpenVisConf-2017.pdf

TomBor avatar Apr 26 '17 08:04 TomBor