全站目录 · 按任务查找
安装与学习路线
首页安装与环境准备选择合适的学习模块模块一『弦图』部分
1.1 输入表与字段含义1.2 生成与导入比对数据1.3 从骨架逐层添加1.4 方向、曲率与避障1.5 筛选与整理连接1.6 原始文件完整流程1.7 弦图综合展示模块二『共线性图』部分
2.1 复用弦图的数据2.2 只替换坐标系,再逐层添加2.3 跨行连接、避障与比例尺2.4 比较基因邻域2.5 局部、锚定与分段2.6 共线性综合展示模块三『质粒图』部分
3.1 DNA、注释与13个参考序列3.2 从圆圈到多层注释3.3 识别特征、引物与酶切3.4 13个质粒参考案例3.5 质粒综合实战按需查阅:数据与图层
数据与坐标导入和转换数据导入核酸和蛋白比对将蛋白区间转换为基因组坐标绘制注释与处理重叠放置和调整标签添加数据轨道设置配色、图例和主题按序列和链设置参数调整图形预览和保存图形学习地图与函数查阅
使用教程函数文档示例图集常见问题迁移到候选 API术语说明更新日志按序列和链设置参数
按序列或链调整几何,保留旧版灵活参数的实用性,同时明确它不适用于所有参数。
本页准备
在新的 R 会话中先运行下方代码,再按页面顺序继续。配色和排版是可选的显示设置,输入只选择需要的列。
准备代码 · 在本页运行一次
代码
library(ggchord)
library(dplyr)
data(seq_data_example)
data(ribbon_data_example)
data(gene_data_example)
seqs <- seq_data_example |>
select(accver, length)
links <- ribbon_data_example |>
select(qaccver, saccver, qstart, qend, sstart, send)
# The fixture preserves biological strands separately from its old display strands.
genes <- gene_data_example |>
transmute(accver, start, end, strand = source_strand)
# Optional appearance choices; none of these columns or scales is required input.
library(ggchord)
seq_palette <- setNames(
c("#E64B35", "#233E4A", "#269B82", "#D59B17"),
c("MT108731.1", "MT118296.1", "OQ646790.1", "OR222515.1")
)
gene_palette <- c("+" = "#CE1536", "-" = "#346B9D", "." = "#8291A6")
library(ggchord)
doc_background <- "#FFFCF5"
identity_palette <- c("#303B71", "#36537D", "#269B82", "#A5D52C", "#ECEB31")
identity_values <- c(0, 0.5, 0.8, 0.9, 1)
identity_breaks <- c(0, 50, 80, 90, 100)
doc_legend_theme <- theme(
legend.title = element_text(size = 13, face = "bold"),
legend.text = element_text(size = 11),
legend.key.width = unit(9, "mm"), legend.key.height = unit(5, "mm"),
legend.spacing.x = unit(9, "mm"), legend.spacing.y = unit(7, "mm"),
legend.margin = margin(l = 4, r = 4, unit = "mm")
)
sequence_guide <- guide_ggchord_legend(nrow = 1, theme = doc_legend_theme)
strand_guide <- guide_ggchord_legend(
nrow = 1, override.aes = list(strand = c("+", "-")), theme = doc_legend_theme
)
identity_guide <- guide_ggchord_colourbar(
position = "left", direction = "vertical",
theme = theme(
legend.key.height = unit(75, "mm"), legend.key.width = unit(5, "mm"),
legend.title = element_text(size = 13, face = "bold"),
legend.text = element_text(size = 11), legend.margin = margin(r = 7, unit = "mm")
)
)
doc_theme <- theme_ggchord_publication(
axis.text = element_text(size = 11),
axis.text.check.overlap = TRUE
) +
theme(
legend.position = "bottom",
legend.title = element_text(size = 13, face = "bold"),
legend.text = element_text(size = 11),
legend.key.width = unit(9, "mm"), legend.key.height = unit(5, "mm"),
legend.spacing.x = unit(9, "mm"), legend.spacing.y = unit(7, "mm"),
legend.box.spacing = unit(6, "mm"),
plot.background = element_rect(fill = doc_background, colour = NA),
panel.background = element_blank(),
plot.title = element_text(face = "bold", size = 18),
plot.subtitle = element_text(size = 10, colour = "#5C625A"),
plot.margin = margin(14, 18, 14, 18)
)
doc_axis <- function(coordinates = "relative") {
scale_seq_position_continuous(
coordinates = coordinates, n.breaks = 3, minor_breaks = NULL,
labels = function(x) format(x, scientific = FALSE, big.mark = ",", trim = TRUE)
)
}旧版称为“灵活的参数格式”。本页用“按序列和链设置参数”明确其用途与边界。
这个能力仍然保留
同一图里常要单独调整某条序列,或分别调整正负链。为这些几何参数保留简洁的 逐序列/逐链写法是合理的;没有必要为了多一条序列而复制整个图层。 推荐先用单值,确实需要差异时用按 accver 命名的向量;正负链使用 +/- 命名向量。
代码
# Sequence IDs remain stable when the data is reordered; positional lists do not.
radii <- setNames(c(1.1, 1, 1, 1), seqs$accver)
widths <- c("+" = .045, "-" = .065)
p_parameters <- ggchord(seq_data = seqs, gene_data = genes) +
geom_seq(seq_radius = radii) +
geom_gene(
width = widths,
position = position_strand(c("+" = .08, "-" = -.1))
) +
geom_seq_label(size = 4) +
scale_seq_colour_manual(values = seq_palette) +
scale_gene_fill_manual(values = gene_palette) +
coord_chord() +
doc_theme
p_parametersradii 的名称对应实际序列 ID, widths 和位移对应链。重新排序时,命名值仍能找到原序列;无名值只按当前位置对应。 这个例子修改的是布局和几何,未把颜色或 theme 参数当成同一套扩展语法。
哪些参数支持
| 接口 | 支持参数 | 匹配范围 |
|---|---|---|
geom_seq() |
seq_radius, seq_curvature, seq_gap, seq_orientation
|
按序列;半径/曲率的效果取决于坐标模式 |
geom_seq_label() |
labels, seq_label_radius, seq_label_rotation, size, seq_label_hjust, seq_label_vjust
|
按序列;seq_label_orientation 是单个模式选项 |
geom_link_ribbon() / geom_link_line()
|
link_gap |
按端点所在序列;控制点不是逐序列标量 |
geom_gene() / geom_feature()
|
width |
按序列,或分别按 +/- 链 |
position_strand() / position_plasmid()
|
offset |
按序列或链;优先使用 Position 而非兼容 offset 入口 |
固定标签 geom_gene_label() / geom_feature_label()
|
label_radial_offset, label_circum_offset, label_circum_limit, label_rotation
|
按序列或链;不代表所有文本参数都接受列表 |
position_track() |
数值型 width, gap
|
原生布局数值可按序列;物理 unit() 使用单个绝对尺寸 |
seq_order 本身就是序列排列,不是上述值的循环规则。自动避让标签的 label_layout 是布局模式;手动角度和偏移请使用固定标签层,不把它们塞进自动标签的 ...。 axis/theme、aesthetic、标度、图例不继承这套列表扩展规则。手工标度本来就支持 按数据类别命名的颜色向量,那属于 ggplot2 的标度语义,见配色教程。
兼容写法与取舍
当前还兼容等长无名向量、按序列名的列表、按序号的列表及等长无名列表;gene/注释 的一项还可包含 +/- 两个值。它们是现有几何接口的兼容形式,不是任意参数的 通用容器。不同参数仍有自己的类型、长度、范围和单位检查。
v0.16.6 RC 审计决定保留这些等价形式,没有新增删除或弃用。位置写法跟随筛选后 当前显示序列顺序;名称匹配 accession ID 时优先按 ID。width/固定标签的逐序列 列表元素应为链值对,单值循环用 list(value);Position offset 还允许逐序列单值 列表。显式按链命名的 Position offset 已带符号,未指定的链或序列补零; position_plasmid() 使用共享 offset,拒绝链值对。键应唯一;"1"、"+"、"-" 这类序列 ID 可能与序号或链简写混淆,按链设置时宜使用按序列命名的嵌套列表。 原生数值型 track width/gap 必须覆盖所有显示序列。这些规则不扩展到 theme。
数值并不共用一个单位:seq_gap 是比例,旋转角度以度表示,物理轨道尺寸使用 明确的 unit()。seq_backbone_gap、seq_backbone_width 是单值样式参数,不在 上述列表规则中。共线性自动方向用 coord_collinear(orientation = "auto"); geom_seq(seq_orientation = ...) 指定的是 +1/-1 数值方向。
完成后检查
命名向量的键应对应实际 accver 或 +/− 链。重排后再次检查匹配;不要将列表规则推广到 theme、scale 或 aesthetic。