Base class for those that create plot compositions
As a user, you will never directly work with this class, except through the operators that it makes possible. The operators are of two kinds:
1. Composing Operators
The combine plots or compositions into a single composition. Both operands are either a plot or a composition.
/
Arrange operands side by side. Powered by the subclass Beside.
|
Arrange operands vertically. Powered by the subclass Stack.
-
Arrange operands side by side and at the same nesting level. Also powered by the subclass Beside.
2. Plot Modifying Operators
The modify all or some of the plots in a composition. The left operand is a composition and the right operand is a plotaddable; any object that can be added to a ggplot object e.g. geoms, stats, themes, facets, … .
&
Add right hand side to all plots in the composition.
*
Add right hand side to all plots in the top-most nesting level of the composition.
+
Add right hand side to the last plot in the composition.
The grouping of the plots is determined by the precedence of the operators which means these two:
p1 / p2 / p3 | p4(p1 / p2 / p3) | p4
are equivalent.
The space allocated within the overall composition is determined by the groups. e.g. Below, the panel in p1 has the same height as the panels of p2 and p3 combined.
(p1 / (p2 / p3)) | p4
p1 | (p2 / p3) | p4
For a 2x wider panel on the left, we group the items on the right.
p1 | ((p2 / p3) | p4)
For a 2x wider panel on the right, we put together the left and right at the same nesting level.
(p1 | (p2 / p3)) - p4
Modifying the composition
Add to the last plot in the composition
When an object that is not a plot or composition is added (+) to the composition, it is added (+) to the last plot in the composition.
You can create space within the composition by adding a plot_spacer or by adjusting plot_margin.
p1 | p2
p1 | plot_spacer() | p2
p1 | (p2 + theme(plot_margin_left=.25))
p1 | (p2 + theme(plot_margin_right=.25))
p1 | (p2 + theme(plot_margin_bottom=.25))
While the margin is added to p2, the height of p1 is adjusted so that the panels align.
How space is allocated
For any composition group, the space is allocated such that the edges of the panels align along one dimension, and the sizes are equal along the other dimension. For example, when a plot has a legend, it is allocated more space so that its panel has the same size as the adjacent panel.
p1 | p2 + aes(color="factor(cyl)")
Making the plot backgrounds visible reveals the size of each plot.