[WIP/RFC] subplot(): separate the definition of the subplots layout from the generation of the resulting plotly object #1100
+234
−136
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The PR extracts
merge_plots()
function from thesubplot()
function, so thatsubplot()
only checks theplots
argument and defines how the plots should be layed out in the merged result. The actual merging of the plotly objects is done bymerge_plots()
function. It enables the users to generate subplots using their own customized layouts.Rationale
I have 2 ggplotly plots, each using

facet_grid()
, I want that the subplots of each ggplotly objects are interleaved in the merged result. Currently,subplot()
does not support faceted ggplotly plots and does only support specifying the layout of the subplots of its arguments. E.g.:Implementation
subplots_info
andaxes_info
define how theplots
should be transformed into the new merged layout:subplots_info
enumerates all the subplots in the merged results: the source plotly object, the reference axes, the shapes and the annotations that belong to the plot.axes_info
enumerates all the axes of theplots
and how they should be renamed and repositioned in the new layout. Repositioning of the axes automatically updates the positions of the linked shapes and annotations (viasubplots_info
).