Skip to contents
Chapters and reference

Module I · Multi-sequence relationships · Section 14 of 16

1.13 Sankey: mirrored interval relationships

Download R scriptIncludes preparation and every page step. File examples need the input bundle; preview and save calls are retained.
On this page

1 Prepare real sources

Data preparation and settings (expand)
R · Example code
library(dplyr)
foundation_source <- ribbon_data_example |>
  mutate(source_hsp_id = paste0("bundled:", row_number()))
foundation_pair <- foundation_source |>
  slice_head(n = 1) |>
  select(qaccver, saccver)
foundation_ids <- c(foundation_pair$qaccver, foundation_pair$saccver)
foundation_seqs <- seq_data_example |>
  filter(accver %in% foundation_ids) |>
  select(accver, length)
foundation_hsp <- foundation_source |>
  filter(qaccver %in% foundation_ids, saccver %in% foundation_ids,
    qaccver != saccver)
foundation_features <- gene_data_example |>
  filter(accver %in% foundation_ids) |>
  transmute(accver, start, end, strand = source_strand, anno)

2 Mirrored two-column relationships

Sankey displays each source once in each column. Query endpoints connect from the left to subject endpoints on the right. Reciprocal input rows stay distinct; same-entity links are excluded by default (self_links=TRUE opts in). Widths come from both real intervals. This layout expresses relationships, not flow conservation. It owns its left/right copies and does not accept between or shared branches in this first version.

R · Example code
p_foundationsankey <- ggchord(foundation_seqs, foundation_hsp) +
  geom_seq() +
  geom_seq_label() +
  geom_link_ribbon() +
  coord_sankey()
view_ggchord(p_foundationsankey, width = 9, height = 8, units = "in")
Mirrored source sequences: query intervals on the left, subject intervals on the right.
Mirrored source sequences: query intervals on the left, subject intervals on the right. · Open full-resolution figure

3 Change only the column gap

R · Example code
p_coursesankeygap <- p_foundationsankey + coord_sankey(column_gap = 0.8)
view_ggchord(p_coursesankeygap, width = 10, height = 8, units = "in")
Change only the column gap

4 Check sources and instances

R · Example code
get_chord_layout(p_foundationsankey)$display_instances

Each of two sources appears once on each side. Do not duplicate seq_data to manufacture observations. Reciprocal records stay distinct. self_links = TRUE enables existing self records without creating any. seq_order contains each source once; between and shared branches are unsupported.

Example: trace both ends of one ribbon back to query and subject and explain why total widths need not be conserved.

Search documentation

↑ ↓ select · Enter open · Esc close; or browse by task. API and functions