scale_x_glycan: Use glycan cartoons as axis labels

View source: R/scale-glycan.R

scale_x_glycanR Documentation

Use glycan cartoons as axis labels

Description

scale_x_glycan() and scale_y_glycan() are discrete position scales that replace text tick labels with compact glycan cartoons. Mapped discrete values and values returned by the scale's labels argument may be glycan structure strings supported by glyparse::auto_parse() or glyrepr::glycan_structure() vectors. X-axis cartoons are vertical and bottom-aligned by default, while y-axis cartoons are horizontal and right-aligned by default. The cartoon orientation and alignment adapt to the displayed axis, including when the axes are swapped by ggplot2::coord_flip().

Usage

scale_x_glycan(
  name = ggplot2::waiver(),
  ...,
  palette = seq_len,
  expand = ggplot2::waiver(),
  position = "bottom",
  sec.axis = ggplot2::waiver(),
  continuous.limits = NULL,
  size = 0.4,
  angle = 0,
  hjust = hjust_red_end(),
  vjust = 0,
  nudge_x = 0,
  nudge_y = 0,
  show_linkage = TRUE,
  red_end = "",
  fuc_orient = c("flex", "up"),
  edge_linewidth = 0.8,
  node_linewidth = 0.8,
  node_size = 1,
  colors = NULL,
  style = NULL
)

scale_y_glycan(
  name = ggplot2::waiver(),
  ...,
  palette = seq_len,
  expand = ggplot2::waiver(),
  position = "left",
  sec.axis = ggplot2::waiver(),
  continuous.limits = NULL,
  size = 0.4,
  angle = 0,
  hjust = 1,
  vjust = vjust_red_end(),
  nudge_x = 0,
  nudge_y = 0,
  show_linkage = TRUE,
  red_end = "",
  fuc_orient = c("flex", "up"),
  edge_linewidth = 0.8,
  node_linewidth = 0.8,
  node_size = 1,
  colors = NULL,
  style = NULL
)

Arguments

name

The name of the scale, displayed as the axis title. Use NULL to remove the title.

...

Arguments passed to ggplot2::scale_x_discrete() or ggplot2::scale_y_discrete(), including breaks and labels.

palette

A palette function that returns discrete position values.

expand

Expansion applied to the discrete position scale.

position

Position of the axis.

sec.axis

A secondary axis specification.

continuous.limits

Continuous limits used to position the discrete scale.

size

Positive scalar that uniformly scales each axis-label cartoon. Defaults to 0.4.

angle

Rotation in degrees applied to each axis-label cartoon, independently of the cartoon orientation. Defaults to 0.

hjust

Horizontal justification. Vertical x-axis cartoons default to hjust_red_end(), while horizontal y-axis cartoons default to 1.

vjust

Vertical justification. Vertical x-axis cartoons default to 0, while horizontal y-axis cartoons default to vjust_red_end().

nudge_x

Horizontal adjustment of each cartoon, in millimetres. Positive values move cartoons to the right. When this moves cartoons toward or away from a y-axis title, the title moves with them to preserve the gap. Defaults to 0.

nudge_y

Vertical adjustment of each cartoon, in millimetres. Positive values move cartoons upward. When this moves cartoons toward or away from an x-axis title, the title moves with them to preserve the gap. Defaults to 0.

show_linkage

Whether to show glycosidic linkage annotations inside the cartoons. Defaults to TRUE.

red_end

Reducing-end annotation passed to glycanGrob(). Use "~" for a wave, or another string to display that text. Defaults to "".

fuc_orient

Fuc-like triangle orientation passed to glycanGrob().

edge_linewidth

Linkage linewidth passed to glycanGrob().

node_linewidth

Node-border linewidth passed to glycanGrob().

node_size

Node-size multiplier passed to glycanGrob().

colors

Optional named character vector of monosaccharide fill colors passed to glycanGrob().

style

A glydraw_style object that supplies rendering options. Its orientation is ignored because each scale determines the axis direction. Explicitly supplied rendering arguments override it.

Value

A ggplot2 discrete position scale.

Examples

glycans <- data.frame(
  structure = c(
    "Gal(b1-3)GalNAc(a1-",
    "Man(a1-3)[Man(a1-6)]Man(b1-4)GlcNAc(b1-"
  ),
  abundance = c(12, 8)
)

ggplot2::ggplot(glycans, ggplot2::aes(x = structure, y = abundance)) +
  ggplot2::geom_col() +
  scale_x_glycan()

glydraw documentation built on July 25, 2026, 9:06 a.m.