Learn R Programming

ggalign

The ggalign package extends ggplot2 to simplify the creation of complex, multi-plot visualizations. Built on the familiar grammar of graphics, it provides intuitive tools to align and organize plots—such as heatmaps, dendrograms, or circular layouts—while handling intricate relationships in multi-omics data, like genomics or microbiomes. Whether you need to stack plots, arrange them around a central figure, or link diverse datasets (e.g., genes to pathways), ggalign offers flexibility and precision with minimal effort.

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. The complete tutorial is available at: https://yunuuuu.github.io/ggalign-book/

  2. For the full reference documentation, visit: https://yunuuuu.github.io/ggalign/

Examples

Compare with other similar tools

Comparison of specifications with other similar tools

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, can be controlled for a single plotAnywhereFour sides, can only be placed on one side at a time
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

722

Version

1.0.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Yun Peng

Last Published

April 10th, 2025

Functions in ggalign (1.0.1)

align_hclust

Reorder or Group observations based on hierarchical clustering
align_panel

Create ggplot object with layout panel data
align_dendro

Plot dendrogram tree
align_kmeans

Split observations by k-means clustering groups.
align_order

Order observations based on weights
active

Plot Adding Context Settings
align_group

Group and align observations based on a group vector
align_order2

Reorders layout observations based on specific statistics.
LayoutProto-class

A Layout object
align

Create a New align Object
coord_circle

Polar Coordinates with Enhanced Controls
circle_layout

Arrange plots in a circular layout
channelGrob

Create a Grob That Spans Multiple Viewports
$,LayoutProto-method

Subset a Layout object
area

Define the plotting areas in align_plots
continuous_limits

Set continuous limits for the layout
circle_switch

Determine the active context of circle layout
align_phylo

Plot Phylogenetics tree
alignpatch

Prepare plots to be aligned with align_plots
align_plots

Arrange multiple plots into a grid
.mark_draw

Define the links to connect the marked observations
element_polygon

Theme Polygon elements
element_curve

Theme curve elements
element_vec

Apply a function to the fields of an element object
facet_sector

Polar coordinates with Facet support
cross_none

Reset layout ordering and panel group
.link_draw

Define the links to connect a pair of observations
fortify_data_frame.character

Build a data frame
fortify_matrix.GISTIC

Build a matrix from a maftools object
fortify_matrix.MAF

Build a Matrix for OncoPrint
fortify_data_frame.default

Build a data frame
fortify_data_frame

Build a data frame
fortify_data_frame.dendrogram

Build a data frame
draw_key_gshape

Key glyphs for legends
fortify_matrix.default

Build a Matrix
fortify_matrix

Build a Matrix
cross_link

Add a plot to connect selected observations
cross_mark

Add a plot to annotate observations
fortify_data_frame.matrix

Build a data frame
fortify_data_frame.phylo

Build a data frame
geom_draw

Layer with Grid or Function
geom_pie

Pie charts
fortify_matrix.phylo

Build a matrix from phylo object
fortify_matrix.matrix_oncoplot

Build a Matrix for OncoPrint
fortify_matrix.matrix_upset

Build a Matrix for UpSet plot
free_align

Free from alignment
fortify_matrix.list_upset

Build a Matrix for UpSet plot
fortify_matrix.matrix

Build a matrix
geom_gshape

Layer with a customized shape graphic using grid functions.
geom_rect3d

Add z-aesthetic for geom_tile
ggalign_attr

Get Data from the Attribute Attached by ggalign
ggfree

Add ggplot to layout without alignment
ggcross

Connect two layout crosswise
geom_subrect

Subdivide Rectangles
ggalign_data_set

Attach supplementary data and levels for ggalign
ggalign

Add ggplot by Aligning discrete or continuous variable
ggalignGrob

Generate a plot grob.
ggalign_stat

Get the statistics from the layout
ggalign-package

ggalign: A 'ggplot2' Extension for Consistent Axis Alignment
ggmark

Add a plot to annotate selected observations
ggoncoplot

Create an OncoPrint
hclust2

Generate Tree Structures with Hierarchical Clustering
is_layout

Reports whether x is layout object
layout-operator

Layout operator
heatmap_layout

Create a heatmap
ggwrap

Wrap Arbitrary Graphics to ggplot
ggupset

Create an UpSet plot
layer_order

Change the layer adding order
inset

Create a ggplot inset
mark_tetragon

Link the observations and the panel with a quadrilateral
layout_design

Define the grid to compose plots in
layout_annotation

Modify components of the layout
layout_expand

Set Expansion for the Layout
mark_triangle

Link the observations and the panel with a triangle
new_tune

Change the shape of the input object
link_line

Link the paired observations with a line
link_tetragon

Link the paired observations with a quadrilateral
memo_order

Sort matrix for better visualization
link_draw

Define the links to connect a pair of observations
patch

Convert Object into a Grob
patch.Heatmap

Convert Object into a Grob
mark_draw

Define the links to connect the marked observations
pair_links

Helper function to create pairs of observation groups
mark_line

Link the observations and the panel with a line
patch.alignpatches

Convert Object into a Grob
layout_title

Annotate the whole layout
patch.pheatmap

Convert Object into a Grob
patch.recordedplot

Convert Object into a Grob
order2

Ordering Permutation
no_expansion

Remove scale expansion
patch.formula

Convert Object into a Grob
patch.grob

Convert Object into a Grob
patch.patch

Convert Object into a Grob
patch.trellis

Convert Object into a Grob
+,ggalign_plot,ANY-method

Add custom objects to ggalign plot
quad_active

Determine the Active Context of Quad-Layout
patch.ggplot

Convert Object into a Grob
scheme_align

Align Specifications in the Layout
scheme_data

Plot data Specifications
quad_init

Initialize Quad-Layout Annotation
patch_titles

Add patch titles to plot borders
tune.MAF

Convert the shape of a MAF for fortify method
theme_no_axes

Remove axis elements
read_example

Read Example Data
raster_magick_interal

Rasterize the input object
patch.patch_ggplot

Convert Object into a Grob
patch.patchwork

Convert Object into a Grob
tune.matrix

Convert the shape of a matrix for fortify method
with_quad

Modify operated Context in quad_layout()
raster_magick

Rasterize the input object
quad_switch

Determine the Active Context of Quad-Layout
stack_switch

Determine the active context of stack layout
stack_layout

Arrange plots horizontally or vertically
scheme_theme

Plot default theme
stack_cross

Arrange plots crosswise horizontally or vertically
quad_layout

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

Change the shape of the input object
scale_gshape_manual

Scale for gshape aesthetic
tune.list

Convert the shape of a list for fortify method
show,ggalign_plot-method

Show ggalign_plot information
reexports

Objects exported from other packages
show,LayoutProto-method

Print Layout object