lets-plot icon indicating copy to clipboard operation
lets-plot copied to clipboard

Add `ggdeck()` for overlaying two on more plots

Open alshan opened this issue 7 months ago • 2 comments

The overlayed plots should have their drawing areas perfectly aligned and should be able to share one or both axis.

This would probably provide a more elegant solution than implementing a traditional 'secondary Y-axis' feature (see #1161).

alshan avatar Apr 29 '25 20:04 alshan

The use case for this issue comes up quite regularly on my end (almost weekly if not daily) when using lets-plot. Is this something where I could help out as a contributor? If so, where would I start?

nsiicm0 avatar Nov 04 '25 11:11 nsiicm0

Hi, @nsiicm0, The good news first: in the recent Lets-Plot v4.8.0, we took a step closer by adding support for optional legend sharing in gggrid() - this would be the default behavior in ggdeck(). Both gggrid() and the proposed ggdeck() are "composite figures" but with different layout approaches.

Also not bad news - several building blocks already exist:

  • Axis limit sharing between subplots is implemented in gggrid() via sharex/sharey parameters, which can likely be adapted for ggdeck()
  • Plot inner area alignment (i.e., "geom" bounds alignment) is already implemented in the gggrid layout via the align parameter and can be reused in some form

Remaining challenges:

  • Shared axis rendering: Axes shouldn't render on top of each other or overlap. Currently this can only be achieved by manual customization of each plot in the deck
  • Transparency: Additional plots should be visually transparent (only the 'base' plot should have a background)
  • Synchronized interactions: Panning and zooming should happen synchronously across all plots in the deck (this is also planned for gggrid)
  • Tooltips: Need to work across all overlaid plots

The task is definitely challenging, but perhaps not everything needs to be in place for an MVP.

Where to start: Here are some useful references to explore:

Python API: gggrid layout configuration Kotlin: Grid layout object configuration Kotlin: Building composite figures

Let me know if you have further questions about the codebase or on the approach generally.

alshan avatar Nov 10 '25 01:11 alshan