Learn R Programming

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

ggalign

This package extends ggplot2 by providing advanced tools for aligning and organizing multiple plots, particularly those that automatically reorder observations, such as dendrogram. It offers fine control over layout adjustment and plot annotations, enabling you to create complex, publication-quality visualizations while still using the familiar grammar of ggplot2.

Why use ggalign?

ggalign focuses on aligning observations across multiple plots. It leverages the "number of observations" in the vctrs package or NROW() function to maintain consistency in plot organization.

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

SpecificationggalignmarsileaaplotComplexHeatmap
Reorder observationsHeatmap Only
Group observations into different panelsHeatmap Only
Clustering algorithmKmeans,Hierarchical Clustering and arbitary algorithmKmeans,Hierarchical Clustering and arbitary algorithm
Legends CreationAutomaticManualAutomaticLimited automatic, requires manual add
Legends PositionAnywhere, can be controlled for a single plotAnywhereAnywhereFour sides, can only be placed on one side at a time
DendrogramTree from both hclust or apehclust onlyTree from both hclust or apehclust 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

774

Version

0.1.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Yun Peng

Last Published

February 6th, 2025

Functions in ggalign (0.1.0)

align_order

Order observations based on weights
LayoutProto-class

A Layout object
active

Plot Adding Context Settings
align_group

Group and align observations based on a group vector
align_hclust

Reorder or Group observations based on hierarchical clustering
align_phylo

Plot Phylogenetics tree
alignpatch

Prepare plots to be aligned with align_plots
area

Define the plotting areas in align_plots
circle_switch

Determine the active context of circle layout
fortify_data_frame

Build a data frame
fortify_data_frame.character

Build a data frame
fortify_data_frame.matrix

Build a data frame
.mark_draw

Define the links to connect the marked observations
draw_key_draw

Key glyphs for legends
continuous_limits

Set continuous limits for the layout
align_plots

Arrange multiple plots into a grid
fortify_matrix.list_upset

Build a Matrix for UpSet plot
align_reorder

Reorders layout observations based on specific statistics.
fortify_matrix.GISTIC

Build a matrix from a maftools object
cross_link

Add a plot to connect selected observations
cross_mark

Add a plot to annotate observations
fortify_matrix.matrix

Build a matrix from a matrix
fortify_matrix.phylo

Build a matrix from phylo object
ggalign-package

ggalign: A 'ggplot2' Extension for Consistent Axis Alignment
fortify_data_frame.phylo

Build a data frame
fortify_matrix.matrix_upset

Build a Matrix for UpSet plot
element_polygon

Theme Polygon elements
ggalign_data_set

Attach supplementary data and levels for ggalign
element_vec

Apply a function to the fields of an element object
ggalign

Add ggplot by Aligning discrete or continuous variable
geom_draw2

Layer with customized draw function
ggalign_stat

Get the statistics from the layout
draw_key_draw2

Key glyphs for legends
ggmark

Add a plot to annotate selected observations
$,LayoutProto-method

Subset a Layout object
ggoncoplot

Create an OncoPrint
layout_annotation

Modify components of the layout
fortify_matrix.MAF

Build a matrix from a maftools object
element_curve

Theme curve elements
geom_pie

Pie charts
mark_triangle

Link the observations and the panel with a triangle
new_tune

Change the shape of the input object
layout_design

Define the grid to compose plots in
circle_layout

Arrange plots in a circular layout
cross_none

Reset layout ordering and panel group
fortify_matrix

Build a Matrix
memo_order

Sort matrix for better visualization
patch.Heatmap

Convert Object into a Grob
ggalignGrob

Generate a plot grob.
.link_draw

Define the links to connect a pair of observations
no_expansion

Remove scale expansion
fortify_matrix.default

Build a Matrix
geom_rect3d

Add z-aesthetic for geom_tile
patch

Convert Object into a Grob
ggalign_attr

Get Data from the Attribute Attached by ggalign
patch.ggplot

Convert Object into a Grob
patch_titles

Add patch titles to plot borders
geom_subrect

Subdivide Rectangles
+,ggalign_plot,ANY-method

Add custom objects to ggalign plot
patch.grob

Convert Object into a Grob
layer_order

Change the layer adding order
quad_layout

Arrange plots in the quad-side of a main plot
fortify_data_frame.default

Build a data frame
fortify_data_frame.dendrogram

Build a data frame
free_align

Free from alignment
ggcross

Connect two layout crosswise
show,LayoutProto-method

Print Layout object
ggfree

Add ggplot to layout without alignment
geom_draw

Layer with Grid or Function
layout-operator

Layout operator
show,ggalign_plot-method

Show ggalign_plot information
ggupset

Create an UpSet plot
layout_expand

Set Expansion for the Layout
quad_switch

Determine the Active Context of Quad-Layout
ggwrap

Wrap Arbitrary Graphics to ggplot
link_draw

Define the links to connect a pair of observations
inset

Create a ggplot inset
link_line

Link the paired observations with a line
is_layout

Reports whether x is layout object
scale_draw_manual

Scale for draw aesthetic
scheme_align

Align Specifications in the Layout
link_tetragon

Link the paired observations with a quadrilateral
patch.patch

Convert Object into a Grob
tune.MAF

Convert the shape of a MAF for fortify method
hclust2

Generate Tree Structures with Hierarchical Clustering
patch.patch_ggplot

Convert Object into a Grob
mark_draw

Define the links to connect the marked observations
quad_active

Determine the Active Context of Quad-Layout
layout_title

Annotate the whole layout
tune

Change the shape of the input object
heatmap_layout

Create a heatmap
patch.recordedplot

Convert Object into a Grob
order2

Ordering Permutation
mark_line

Link the observations and the panel with a line
pair_links

Helper function to create pairs of observation groups
scheme_data

Plot data Specifications
scheme_theme

Plot default theme
stack_cross

Arrange plots crosswise horizontally or vertically
mark_tetragon

Link the observations and the panel with a quadrilateral
stack_layout

Arrange plots horizontally or vertically
patch.trellis

Convert Object into a Grob
patch.formula

Convert Object into a Grob
patch.alignpatches

Convert Object into a Grob
patch.patchwork

Convert Object into a Grob
patch.pheatmap

Convert Object into a Grob
read_example

Read Example Data
raster_magick

Rasterize the input object
raster_magick_interal

Rasterize the input object
tune.list

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

Convert the shape of a matrix for fortify method
reexports

Objects exported from other packages
quad_init

Initialize Quad-Layout Annotation
stack_switch

Determine the active context of stack layout
with_quad

Modify operated Context in quad_layout()
theme_no_axes

Remove axis elements
align_kmeans

Split observations by k-means clustering groups.
align_panel

Create ggplot object with layout panel data
align

Create a New align Object
align_dendro

Plot dendrogram tree