Skip to content
This repository has been archived by the owner on Nov 12, 2020. It is now read-only.

Layering: Support? #31

Open
saptarshiguha opened this issue May 17, 2018 · 5 comments
Open

Layering: Support? #31

saptarshiguha opened this issue May 17, 2018 · 5 comments

Comments

@saptarshiguha
Copy link

Hello,
Thanks much for the great package (vegalite is lovely). Do you have plans to support (or have i missed it?) layering (see https://vega.github.io/vega-lite/docs/layer.html )

@saptarshiguha
Copy link
Author

saptarshiguha commented May 17, 2018

For example, i forked the repo and added this

mark_rule <- function(vl, ...) {
  vl <- mark(vl, mark="rule", ...)
  return(vl)
}

and this code does indeed replicate the example in the above link

p1 <- vegalite(viewport_width=800, viewport_height=600) %>%
    view_size(700,500)
p2 <-add_data(p1,"https://vega.github.io/vega-editor/app/data/stocks.csv") %>%
    encode_x("date", "temporal") %>%
    encode_y("price", "quantitative") %>%
    encode_color("symbol","nominal") %>%
    mark_line()

p3 <-add_data(p1,"https://vega.github.io/vega-editor/app/data/stocks.csv") %>%
    encode_y("price", "quantitative",aggregate='mean') %>%
    encode_size(value=2) %>%
    encode_color("symbol", "nominal") %>%
    mark_rule()

from_spec(
    sprintf("{\"layer\":[%s]}",
        paste(to_spec(p2)[[1]],
              to_spec(p3)[[1]],sep=",",collapse="")))

However, this means replicated add_data and it would be nice to have one description field etc. Not sure of how the API call would look like to support layers.

@jsonbecker
Copy link
Collaborator

With vegalite 2.0 now in, it's conceptually possible. But we have struggled with what the layer API should look like as you stated.

@jsonbecker
Copy link
Collaborator

See also #16

@saptarshiguha
Copy link
Author

Yes, API design is difficult. As a stop gap, is there a way to return composable JSON that i could combine using list statements and then recombine into vega using from_spec?

The above code with sprintf and constructing JSON strings is a bit kludgy. I'm thinking i could play with layers and with the experience imagine an API that might suit my workflow.

Maybe there already is an elegant way using the current rvegalite api to do the above.

thanks

@jsonbecker
Copy link
Collaborator

The vegalite object passed around in these functions is a list that is designed to tranlaste to the JSON object. Check out to_spec to see.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants