Us­ing Lay­ers

Linux Format - - Coding Academy -

Vega and Ve­gaLite en­able you to have lay­ers in your plots. The lay­ers. html file will show­case how you can add lay­ers in the out­put of Vega Lite. No­tice the use of the layer block that de­fines two in­de­pen­dent ob­jects. Apart from the use of the layer key­word, the in­ter­nal for­mat that’s used in the lay­ers.html file is as fol­lows:

“layer”: [ { Code for Layer 1 }, { Code for Layer 2 } ], “re­solve”: {“scale”: {“y”: “in­de­pen­dent”}}

All the magic hap­pens by defin­ing two dif­fer­ent ob­jects in­side the layer block. Each ob­ject can have its own type of mark and its own en­cod­ing blocks.

Fi­nally, the op­tions in the re­solve block spec­ify that the scale do­mains of the two lay­ers should be united so that the axes and the le­gends of the two lay­ers can be merged. If you com­ment out the re­solve line, the gen­er­ated out­put will look less pro­fes­sional. The in­de­pen­dent value sig­ni­fies the use of in­de­pen­dent axes and le­gends for the two lay­ers.

Please note that the out­put might look bet­ter if you’re lay­er­ing dif­fer­ent kinds of plots. Put sim­ply, don’t layer three bar charts one over the other, be­cause you might not be able to see all the in­for­ma­tion. Sim­i­larly, avoid putting grids on plots that have lay­ers.

Newspapers in English

Newspapers from Australia

© PressReader. All rights reserved.