Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to encode the Trellis Scatter Plot example #5

Closed
DougBurke opened this issue Jul 23, 2019 · 4 comments
Closed

How to encode the Trellis Scatter Plot example #5

DougBurke opened this issue Jul 23, 2019 · 4 comments

Comments

@DougBurke
Copy link
Contributor

Apologies if I'm missing something obvious (I am using hvega rather than your module, so it could well be all my own fault ...), but I can't see how to encode the https://vega.github.io/vega-lite/examples/trellis_scatter.html example (which has changed since I last looked at it). The JSON is

{
  "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
  "data": {"url": "data/movies.json"},
  "mark": "point",
  "columns": 2,
  "encoding": {
    "facet": {"field": "MPAA_Rating","type": "ordinal"},
    "x": {"field": "Worldwide_Gross","type": "quantitative"},
    "y": {"field": "US_DVD_Sales","type": "quantitative"}
  }
}

and the trouble I'm having is creating the facet entry in the encoding object. I can see column and row, but facet and facetFlow don't fit here (since they're not ... -> List LabelledSpec -> List LabelledSpec).

The closest I could find is facet3 in elm-vegalite/test-gallery/src/GalleryFacet.elm, but that follows the "old" version of this plot (which had a column field instead of facet).

@jwoLondon
Copy link
Member

Thanks for raising this. The example you give is what I think the Vega-Lite team call a wrapped facet, which then gets translated into a spec that uses the facet operator pattern. In elm-vegalite, I would normally just code with the facet operator pattern directly:

facetTwoCols : Spec
facetTwoCols =
    let
        data =
            dataFromUrl "https://vega.github.io/vega-lite/data/movies.json"

        enc =
            encoding
                << position X [ pName "Worldwide_Gross", pMType Quantitative ]
                << position Y [ pName "US_DVD_Sales", pMType Quantitative ]
    in
    toVegaLite
        [ data []
        , columns (Just 2)
        , facetFlow [ fName "MPAA_Rating", fMType Ordinal ]
        , specification (asSpec [ enc [], point [] ])
        ]

(As an aside, none of the wrapped facet examples from the Vega-Lite documentation pages are rendered correctly in Safari although they do render in Chrome.)

To me, the facet operator patterns feels neater in that it separates the specification for each faceted plot from the faceting specification. The question is, how useful/important would it be for elm-vegalite and hvega to support the wrapped facet pattern directly?

@jwoLondon
Copy link
Member

Could create a wrappedFacet function that serves this role. For example,

enc =
    encoding
        << position X [ pName "Worldwide_Gross", pMType Quantitative ]
        << position Y [ pName "US_DVD_Sales", pMType Quantitative ]
        << wrappedFacet [fName "MPAA_Rating", fMType Ordinal]
Pros Cons
Provides a direct mapping to Vega-Lite JSON eqivalent Not strictly necessary as can always replicate with facet operator pattern
Slightly more compact Increases surface area of API
Possibly easier to remember than facet operator pattern Yet another variation of faceting that added unnecessary complexity to 'faceting' as a process

What do you think?

@DougBurke
Copy link
Contributor Author

I still don't have a feel for the full Vega-Lite schema/capabilities, so I am wary of suggesting API changes that I don't really understand! For the examples I am comparing the JSON output of hvega to that given on the example page, which is where I noticed the problem (essentially your first row in the table above), but as you said it is more important that the functionality be available, rather than a "bit-identical" mapping to the examples.

@jwoLondon
Copy link
Member

Let's close it for now as there doesn't appear to be a compelling reason to introduce a wrapped facet function.

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

No branches or pull requests

2 participants