In alignpatches(), each subplot require a Patch object for proper
alignment and layout operations. Patch object is a
ggproto() object that provides the core methods for
arranging and aligning the plots.
Fields
optionsA
patch_optionsobject used to align the plot.set_optionsDescription
Sets multiple options at once in the
optionsfield. This method allows you to provide one or more key-value pairs, where each key represents an option name and its corresponding value is assigned to that option.Arguments
...: Key-value pairs to set specific properties of theoptionsobject. Each argument should be of the formname = value, wherenameis the option name andvalueis the value to assign to it.
set_optionDescription
Sets a specific option in the
optionsfield. This method allows you to modify individual properties of theoptionsobject by providing a key-value pair.Arguments
name: The name of the option to be set (as a character string).value: The value to assign to the specified option.check: Logical, ifTRUE(default), checks the validity of the option before assigning it. Set toFALSEto bypass the check.
get_optionDescription
Retrieves a specific option from the
optionsfield.Arguments
option: The name of the option to retrieve.
Value The value of the specified option.
setupDescription
(Optional method) Sets up the
optionsanddatafor the plot.Arguments
options: Apatch_optionsobject that contains various layout options.
gtableDescription
(Required method) Constructs a
standardized gtableobject.Value A standardized
gtableobject, or a simplegrobobject.The returned object represents the graphical structure, which can either be a full table-based layout (
gtable) for more complex arrangements or a simpler graphical object (grob) when only basic plot elements are involved.decompose_guidesDescription
(Optional method) Collects guide legends and optionally removes the space they occupy.
This method extracts guide legends based on the sides specified in the
guidesargument. After collecting the guides, the corresponding space in thegtis removed to free up space, except for guides placedinsidethe panel.Arguments
gt: Agtableobject, usually returned byself$gtable().
Value A list with:
gt: The updated gtable with guide legends removed (if applicable).guides: A named list of collected guide grobs corresponding to the sides specified inguides(orNULLif absent).
tagAdd a Tag to a
gtableDescription: This function adds a tag to a given
gtableat a specified position. The tag is added only if thegtableis standardized (i.e., it has the expected number of rows and columns)..Arguments:
gt: Agtableobject to which the tag will be added.label: A string representing the label or content for the tag.t,l,b,r: Numeric values representing the top, left, bottom, and right margins (coordinates) for placing the tag on thegtable.z: A numeric value representing the z-order, controlling the stacking order of the tag relative to other elements in thegtable.
Value: The modified
gtablewith the tag added. If thegtableis not standardized (i.e., it doesn't meet the row/column requirements), the function returns the originalgtablewithout modification.panel_sizesDescription
This method retrieves the panel sizes (widths and heights) of a
gtableorgrobobject.Arguments
gt: Agtableobject, usually returned byself$decompose_guides().
Value A list with components:
widths: The panel widths as a unit objectheights: The panel heights as a unit object
adjust_panel_width/adjust_panel_heightDescription
(Optional method) In most cases, the panel sizes do not need to be manually adjusted when aligning, as long as their border sizes are consistent. However, for
gtableobjects with absolute panel sizes, the panel sizes must be directly set to ensure that all plot panels fill in. This is particularly important when the specified and desired panel sizes are in absolute units. The method is only called when the plot does not span across multiple areas.Arguments
panel_widths/panel_heights: Unit objects representing the panel widths or heights of the underlyinggtableobject. These values correspond to thewidths/heightsfields returned by the$panel_sizes()method.panel_width/panel_height: Unit objects representing the desired panel size. If the internal numeric value isNA, the size will be computed based onpanel_widths/panel_heights.
Value The panel width/height as a unit object
respect_panelDescription
(Optional method) In most cases, panel sizes do not need to be manually adjusted when aligning panels, as long as their border sizes are consistent. However, for
gtableswith a fixed panel aspect ratio, if the internal numeric value of the input panel sizes (eitherpanel_widthorpanel_heightisNA), that dimension will be inferred while maintaining the aspect ratio, particularly for single-panel layouts.Arguments
gt: Agtableobject, usually returned byself$decompose_guides().panel_width/panel_height: Unit objects specifying the desired panel size. If the internal numeric value of either isNA, the size is computed from the gtable (gt).
Value A list with components:
width: The panel width as a unit objectheight: The panel height as a unit objectrespect: IfTRUE, the aspect ratio was enforced
border_sizesDescription
(Optional method) retrieve the border sizes of a gtable.
Arguments
gt: Agtableobject, usually returned byself$decompose_guides().
Value A list with components:
top:unitvalues for the top borders orNULL.left:unitvalues for the left borders orNULL.bottom:unitvalues for the bottom borders orNULL.right:unitvalues for the right borders orNULL.
align_borderDescription
(Optional method) This method modifies the top, left, bottom, and right border sizes of the underlying gtable (
gt) by replacing corresponding entries in itsheightsandwidthsvectors..Arguments
gt: Agtableobject, usually returned byself$decompose_guides().t,l,b,r: Optional numeric vectors specifying new sizes for the top, left, bottom, and right borders, respectively. Each vector replaces the corresponding entries ingt$heightsorgt$widths.
Value A modified
gtableobject.placeDescription (Optional method) Inserts the patch's gtable (including optional background) into the target canvas gtable.
This method places the patch's gtable into a specified location of another gtable, preserving the background and plot layers separately if a background exists. The
t,l,b,rarguments specify the position in the target gtable, andbg_z/plot_zdefine the stacking order (z-order) for background and plot.Arguments
gtable: the target canvas gtable into which the patch will be inserted.gt: Agtableobject, usually returned byself$align_border().t,l,b,r: Integer positions (top, left, bottom, right) specifying where to insert the patch in the target gtable.i: Index of the current patch, used to generate unique grob names.bg_z: Z-order for the background grob (default1L).plot_z: Z-order for the plot grob (default2L).options: Apatch_optionsobject containing various layout options. Typically, this is the value returned by the subplot'sself$setup()method.
Details
If the patch includes a grob named
"background", it is separated from the main plot and inserted independently from the plot grob.If no background is present, the entire gtable is inserted as the plot grob.
Value The modified target canvas gtable with the patch's gtable added.
decompose_bgDescription Separates the background grob (if present) from the main gtable.
Value A list with:
bg: The background grob (orNULLif absent)gt: The gtable with background removed
place_bgDescription Adds the background grob into the target gtable.
place_gtDescription Adds the main plot gtable into the target gtable.
is_alignpatchesDescription
Checks whether the object inherits from the
alignpatches()Patchrepresentation.If
TRUE, theself$alignpatcheswill includepatches,gt_list, andborders_list. For an example of how these are used, refer to thepatch.ggalign_free_labfunction in thealignpatch-free-lab.Rscript.Value Logical value (
TRUEorFALSE) indicating whetherselfis aPatchAlignpatchesobject.
