Learn R Programming

⚠️There's a newer version (1.2.0) of this package.Take me there.

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.1.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Yun Peng

Last Published

September 11th, 2025

Functions in ggalign (1.1.0)

align_panel

Create ggplot object with layout panel data
area

Define the plotting areas in align_plots
align_kmeans

Split observations by k-means clustering groups.
align_phylo

Plot Phylogenetics tree
align_plots

Arrange multiple plots into a grid
align_order2

Reorders layout observations based on specific statistics.
circle_genomic

Create a Circular Layout for Genomic Data
circle_layout

Arrange plots in a circular layout
alignpatch

Prepare plots to be aligned with align_plots
element_vec

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

Define the links to connect a pair of observations
draw_key_gshape

Key glyphs for legends
circle_switch

Determine the active context of circle layout
coord_circle

Polar Coordinates with Enhanced Controls
cross_mark

Add a plot to annotate observations
continuous_limits

Set continuous limits for the layout
cross_link

Add a plot to connect selected observations
cross_none

Reset layout ordering and panel group
.mark_draw

Define the links to connect the marked observations
align_order

Order observations based on weights
fortify_data_frame.default

Build a data frame
fortify_matrix.GISTIC

Build a matrix from a maftools object
fortify_data_frame.GRanges

Build a data frame
facet_sector

Polar coordinates with Facet support
fortify_data_frame.matrix

Build a data frame
fortify_data_frame

Build a data frame
fortify_data_frame.character

Build a data frame
fortify_data_frame.dendrogram

Build a data frame
fortify_matrix.MAF

Build a Matrix for OncoPrint
fortify_data_frame.phylo

Build a data frame
fortify_matrix.matrix_oncoplot

Build a Matrix for OncoPrint
fortify_matrix.default

Build a Matrix
fortify_matrix

Build a Matrix
genomic_density

Calculate Genomic Region Density
fortify_matrix.list_upset

Build a Matrix for UpSet plot
fortify_matrix.matrix

Build a matrix
fortify_matrix.matrix_upset

Build a Matrix for UpSet plot
geom_draw

Layer with Grid or Function
free_align

Free from alignment
genomic_dist

Calculate inter-region distances for genomic rainfall plots
geom_gshape

Layer with a customized shape graphic using grid functions.
ggalign

Add ggplot by Aligning discrete or continuous variable
ggalign_attr

Get Data from the Attribute Attached by ggalign
ggalignGrob

Generate a plot grob.
geom_rect3d

Add z-aesthetic for geom_tile
ggalign-package

ggalign: A 'ggplot2' Extension for Composable Visualization
ggalign_data_set

Attach supplementary data and levels for ggalign
geom_subrect

Subdivide Rectangles
geom_pie

Pie charts
geom_magick

Draw images as point shapes using magick
ggalign_stat

Get the statistics from the layout
heatmap_layout

Create a heatmap
ggmark

Add a plot to annotate selected observations
ggfree

Add ggplot to layout without alignment
ggcross

Connect two layout crosswise
hclust2

Generate Tree Structures with Hierarchical Clustering
ggwrap

Wrap Arbitrary Graphics to ggplot
ggoncoplot

Create an OncoPrint
ggupset

Create an UpSet plot
inset

Create a ggplot inset
layout_design

Define the grid to compose plots in
layer_order

Change the layer adding order
layout_title

Annotate the whole layout
layout-operator

Layout operator
layout_theme

Modify theme of the layout
layout_tags

Control Plot Tagging in Layouts
layout_annotation

Add layout annotation
is_layout

Reports whether x is layout object
link_draw

Define the links to connect a pair of observations
mark_tetragon

Link the observations and the panel with a quadrilateral
mark_line

Link the observations and the panel with a line
layout_expand

Set Expansion for the Layout
new_tune

Change the shape of the input object
mark_draw

Define the links to connect the marked observations
mark_triangle

Link the observations and the panel with a triangle
memo_order

Sort matrix for better visualization
patch.Heatmap

Convert Object into a Grob
patch.ggplot

Convert Object into a Grob
patch.grob

Convert Object into a Grob
link_line

Link the paired observations with a line
patch.patch_ggplot

Convert Object into a Grob
magickGrob

Rasterize a grob object with magick
patch.ggalign::AlignPatches

Convert Object into a Grob
order2

Ordering Permutation
link_tetragon

Link the paired observations with a quadrilateral
patch

Convert Object into a Grob
no_expansion

Remove scale expansion
patch.patch

Convert Object into a Grob
patch.patchwork

Convert Object into a Grob
patch.pheatmap

Convert Object into a Grob
patch.formula

Convert Object into a Grob
pair_links

Helper function to create pairs of observation groups
plot_add_scheme

Apply a Scheme to a plot
quad_layout

Arrange plots in the quad-side of a main plot
patch.recordedplot

Convert Object into a Grob
plot_ideogram

Add an aligned cytoband ideogram plot
patch.trellis

Convert Object into a Grob
quad_active

Determine the Active Context of Quad-Layout
quad_init

Initialize Quad-Layout Annotation
patch_titles

Add patch titles to plot borders
quad_scope

Modify operated Context in quad_layout()
read_example

Read Example Data
reexports

Objects exported from other packages
scale_gshape_manual

Scale for gshape aesthetic
raster_magick

Rasterize the ggplot layers
scheme_data

Plot data Specifications
quad_switch

Determine the Active Context of Quad-Layout
scheme_inherit

Inherit a scheme from a parent
scale_z_continuous

z scales
scheme_align

Align Specifications in the Layout
stack_cross

Arrange plots crosswise horizontally or vertically
tune

Change the shape of the input object
scheme_theme

Plot default theme
stack_switch

Determine the active context of stack layout
stack_genomic

Create a stack Layout for Genomic Data
stack_layout

Arrange plots horizontally or vertically
theme_no_axes

Remove axis elements
scheme_init

Initialize a scheme object
tune.MAF

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

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

Convert the shape of a matrix for fortify method
with_quad

Create ggplot object with layout panel data
scheme_update

Update the scheme
align

Create a New CraftBox Object with CraftAlign craftsman
align_hclust

Reorder or Group observations based on hierarchical clustering
align_dendro

Plot dendrogram tree
active

Plot Adding Context Settings
align_group

Group and align observations based on a group vector
Layout-subset

Subset a Layout object
LayoutProto

A Layout object
Scheme

Abstract Scheme Class
Schemes

A container for multiple layout schemes
Craftsman

Craftsman Object for Layout Management