Learn R Programming

ggalign

The ggalign package provides an integrative framework for composable visualization, enabling the construction of complex multi-plot layouts—including insets, circular arrangements, and multi-panel compositions. Built on the grammar of graphics, it introduces tools to align, stack, and nest plots, making it easy to link related views, overlay clustering results, or highlight shared patterns. Designed for high-dimensional data contexts such as genomics, transcriptomics, and microbiome studies, it simplifies the creation of richly annotated, publication-ready figures from diverse visual components.

Why use ggalign?

ggalign focuses on aligning observations across multiple plots. If you’ve ever struggled with aligning plots with self-contained ordering (like dendrogram), or applying consistent grouping or ordering across multiple plots (e.g., with k-means clustering), ggalign is designed to make this easier. The package integrates seamlessly with ggplot2, providing the flexibility to use its geoms, scales, and other components for complex visualizations.

Installation

You can install ggalign from CRAN using:

install.packages("ggalign")

Alternatively, install the development version from r-universe with:

install.packages("ggalign",
    repos = c("https://yunuuuu.r-universe.dev", "https://cloud.r-project.org")
)

or from GitHub with:

# install.packages("remotes")
remotes::install_github("Yunuuuu/ggalign")

Learning ggalign

  1. Full reference documentation: https://yunuuuu.github.io/ggalign/
  2. Complete tutorial book: https://yunuuuu.github.io/ggalign-book/
  3. Gallery of examples: https://yunuuuu.github.io/ggalign-gallery/

Design features

Examples

Comparison with other composable visualization tools

Feature and specification comparison

SpecificationggalignmarsileaComplexHeatmap
Reorder observationsHeatmap Only
Group observations into different panelsHeatmap Only
Clustering algorithmKmeans,Hierarchical Clustering and arbitary algorithmKmeans,Hierarchical Clustering and arbitary algorithm
Legends CreationAutomaticAutomaticLimited automatic, requires manual add
Legends PositionAnywhere; independently controllable per plotAnywhereFixed to one of four sides
DendrogramTree from both hclust or apehclust onlyhclust only
Tanglegram
3D Heatmap
Oncoplot
UpSet plot

Acknowledgements

I would like to express my sincere gratitude to the contributors of the ggplot2 project for providing a powerful and flexible framework for data visualization in R. Their work laid the foundation for the functionality and design of this package. I would also like to thank the patchwork project, from which the core coding for the plot composer was adapted. The patchwork library provided a useful mechanism for combining and aligning plots, which was modified to suit the needs of this package. Without the contributions of these open-source projects, this package would not have been possible.

Additionally, I would like to extend my heartfelt thanks to @teunbrand, who has fulfilled my numerous feature requests, and assisted with the integration of new functions into ggplot2.

Copy Link

Version

Install

install.packages('ggalign')

Monthly Downloads

1,212

Version

1.2.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Yun Peng

Last Published

October 18th, 2025

Functions in ggalign (1.2.0)

as_grob.formula

Convert Object into a Grob
align_order2

Reorders layout observations based on specific statistics.
align_order

Order observations based on weights
as_grob.patch

Convert Object into a Grob
as_grob.gList

Convert Object into a Grob
as_grob.grob

Convert Object into a Grob
as_grob.ggplot

Convert Object into a Grob
as_grob.patch_ggplot

Convert Object into a Grob
circle_switch

Determine the active context of circle layout
alignpatches

Arrange multiple plots into a grid
continuous_limits

Set continuous limits for the layout
cross_mark

Add a plot to annotate observations
cross_none

Reset layout ordering and panel group
as_grob.pheatmap

Convert Object into a Grob
as_grob.patchwork

Convert Object into a Grob
cross_link

Add a plot to connect selected observations
as_grob.ggalign::alignpatches

Convert Object into a Grob
coord_circle

Polar Coordinates with Enhanced Controls
as_grob.trellis

Convert Object into a Grob
as_grob.recordedplot

Convert Object into a Grob
circle_layout

Arrange plots in a circular layout
circle_genomic

Create a Circular Layout for Genomic Data
fortify_data_frame.phylo

Build a data frame
fortify_data_frame.dendrogram

Build a data frame
fortify_data_frame.default

Build a data frame
facet_sector

Polar coordinates with Facet support
draw_key_gshape

Key glyphs for legends
.mark_draw

Define the links to connect the marked observations
fortify_data_frame

Build a data frame
element_vec

Apply a function to the fields of an element object
.link_draw

Define the links to connect a pair of observations
fortify_matrix.matrix_oncoplot

Build a Matrix for OncoPrint
fortify_data_frame.character

Build a data frame
fortify_matrix

Build a Matrix
fortify_matrix.default

Build a Matrix
fortify_matrix.matrix_upset

Build a Matrix for UpSet plot
fortify_matrix.list_upset

Build a Matrix for UpSet plot
fortify_matrix.matrix

Build a matrix
fortify_data_frame.GRanges

Build a data frame
fortify_matrix.MAF

Build a Matrix for OncoPrint
fortify_matrix.GISTIC

Build a matrix from a maftools object
fortify_data_frame.matrix

Build a data frame
geom_subrect

Subdivide Rectangles
genomic_dist

Calculate inter-region distances for genomic rainfall plots
genomic_density

Calculate Genomic Region Density
geom_pie

Pie charts
geom_draw

Layer with Grid or Function
ggalign-package

ggalign: A 'ggplot2' Extension for Composable Visualization
free_align

Free from alignment
geom_gshape

Layer with a customized shape graphic using grid functions.
ggalignGrob

Generate a plot grob.
ggalign

Add ggplot by Aligning discrete or continuous variable
geom_rect3d

Add z-aesthetic for geom_tile
hclust2

Generate Tree Structures with Hierarchical Clustering
ggwrap

Wrap Arbitrary Graphics to ggplot
geom_magick

Draw images as point shapes using magick
ggalign_attr

Get Data from the Attribute Attached by ggalign
ggalign_data_set

Attach supplementary data and levels for ggalign
ggfree

Add ggplot to layout without alignment
layout_expand

Set Expansion for the Layout
layer_order

Change the layer adding order
ggupset

Create an UpSet plot
ggoncoplot

Create an OncoPrint
layout_design

Define the grid to compose plots in
ggmark

Add a plot to annotate selected observations
is_layout

Reports whether x is layout object
layout_tags

Control Plot Tagging in Layouts
link_line

Link the paired observations with a line
mark_line

Link the observations and the panel with a line
layout_theme

Modify theme of the layout
layout-operator

Layout operator
ggalign_stat

Get the statistics from the layout
ggcross

Connect two layout crosswise
layout_annotation

Add layout annotation
layout_title

Annotate the whole layout
mark_tetragon

Link the observations and the panel with a quadrilateral
heatmap_layout

Create a heatmap
inset

Create a ggplot inset
new_tune

Change the shape of the input object
no_expansion

Remove scale expansion
link_draw

Define the links to connect a pair of observations
link_tetragon

Link the paired observations with a quadrilateral
patch_title

Add patch titles to plot borders
patch

Get Patch representation
mark_draw

Define the links to connect the marked observations
quad_active

Determine the Active Context of Quad-Layout
magickGrob

Rasterize a grob object with magick
plot_ideogram

Add an aligned cytoband ideogram plot
plot_add_scheme

Apply a Scheme to a plot
memo_order

Sort matrix for better visualization
mark_triangle

Link the observations and the panel with a triangle
scale_gshape_manual

Scale for gshape aesthetic
scheme_align

Align Specifications in the Layout
scheme_data

Plot data Specifications
read_example

Read Example Data
reexports

Objects exported from other packages
scale_z_continuous

z scales
stack_switch

Determine the active context of stack layout
stack_layout

Arrange plots horizontally or vertically
quad_init

Initialize Quad-Layout Annotation
scheme_init

Initialize a scheme object
scheme_inherit

Inherit a scheme from a parent
tune.matrix

Convert the shape of a matrix for fortify method
tune.list

Convert the shape of a list for fortify method
pair_links

Helper function to create pairs of observation groups
quad_scope

Modify operated Context in quad_layout()
quad_layout

Arrange plots in the quad-side of a main plot
stack_cross

Arrange plots crosswise horizontally or vertically
order2

Ordering Permutation
with_quad

Create ggplot object with layout panel data
stack_genomic

Create a stack Layout for Genomic Data
quad_switch

Determine the Active Context of Quad-Layout
tune

Change the shape of the input object
tune.MAF

Convert the shape of a MAF for fortify method
raster_magick

Rasterize the ggplot layers
scheme_theme

Plot default theme
standardized_gtable

Standardized gtable Representation
scheme_update

Update the scheme
theme_no_axes

Remove axis elements
Schemes

A container for multiple layout schemes
align_group

Group and align observations based on a group vector
active

Plot Adding Context Settings
align_dendro

Plot dendrogram tree
align_hclust

Reorder or Group observations based on hierarchical clustering
LayoutProto

A Layout object
Layout-subset

Subset a Layout object
Scheme

Abstract Scheme Class
Craftsman

Craftsman Object for Layout Management
align

Create a New CraftBox Object with CraftAlign craftsman
align_kmeans

Split observations by k-means clustering groups.
align_phylo

Plot Phylogenetics tree
as_grob

Convert Object into a Grob
align_panel

Create ggplot object with layout panel data
area

Define the plotting areas
as_grob.Heatmap

Convert Object into a Grob