全站目录 · 按任务查找
安装与学习路线
首页安装与环境准备选择合适的学习模块模块一『弦图』部分
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)
feature_palette <- c(
CDS = "#993366", promoter = "#31849B", rep_origin = "#F1E51D",
primer_bind = "#A020F0", misc_feature = "#A6ACB3", protein_bind = "#31849B"
)
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)
)
}
library(dplyr)
data(plasmid_example_pUC19)
plasmid_seq <- plasmid_example_pUC19 |>
select(accver, length)
feature_source <- find_common_features(plasmid_example_pUC19)
features <- feature_source |>
select(accver, start, end, strand, type, anno)保留注释语义
本页准备代码已加载 pUC19 的实际注释。 这里保留 pUC19 中实际重叠的注释和原本未知的链方向。 几何和填色分别映射同一类别;显式固定 shape 会覆盖 shape 映射。
代码
stack_features <- features |>
select(accver, start, end, strand, type, anno)
stack_position <- position_feature_stack(spacing = .12)
feature_shapes <- setNames(ifelse(names(feature_palette) == "CDS", "arrow", "block"), names(feature_palette))
p_stack <- ggchord(seq_data = plasmid_seq) +
geom_seq(show.legend = FALSE) +
geom_feature(aes(feature_fill = type, feature_shape = type),
data = stack_features,
width = .08, position = stack_position
) +
geom_feature_label_repel(data = stack_features, position = stack_position, size = 3.8, label_fit = "shrink", label_min_size = 2.8) +
scale_feature_shape_manual(values = feature_shapes) +
scale_feature_fill_manual(values = feature_palette) +
coord_collinear() +
doc_axis() +
doc_theme
p_stack
position_feature_stack() 解决注释轨道重叠。标签层使用同一 Position,让文字锚点 跟随轨道。标签子集或重排时优先提供唯一 feature_id。严格的 gene 快捷层要求 已知 +/-,通用注释保留未知/双向语义。
按含义选择形状
| 几何 | 常见用途 | 重要区别 |
|---|---|---|
arrow, compact_arrow
|
有方向的编码/注释区间 | 已知方向来自证据,不由显示猜测 |
block, capped_line
|
区域或不填充区间 | 选择形状不推断生物学功能 |
promoter_arrow, primer_arrow, primer_arc
|
已声明的启动子/引物式注释 | 计算匹配与绘图分开 |
marker, chevron, lollipop
|
自定义区间/类点强调 | 保留真实区间元数据,显示形状属于映射 |
geom_gene()、geom_feature_plasmid() 是有用预设,默认值并不相同。 position_strand() 提供带符号位移,position_plasmid() 提供圆图放置预设, 后者不构成第四类坐标模式。
高亮区间而不改写观测
代码
regions <- tibble(
accver = links$qaccver[1], start = min(links$qstart[1], links$qend[1]),
end = max(links$qstart[1], links$qend[1]), category = "alignment interval"
)
p_decorated <- ggchord(seq_data = seqs, ribbon_data = links) +
geom_seq_region(aes(region_fill = category), data = regions, colour = NA) +
geom_link_ribbon(fill = "#6BAFA6", alpha = .4) +
geom_seq() +
geom_seq_label(size = 4) +
scale_region_fill_manual(values = c("alignment interval" = "#F4D35E")) +
scale_seq_colour_manual(values = seq_palette) +
geom_seq_scale(length = 10000) +
coord_collinear() +
doc_axis() +
doc_theme
p_decorated
区域叠层有自己的数据和 region_fill 标度。geom_seq_label() 命名序列, geom_seq_center_label() 在单圆图中心提供名称/长度,geom_seq_break() 标记裁剪或 分段末端。geom_seq_scale() 是仅用于共线性图的独立 bp 参照条,与控制序列基因组轴 的 scale_seq_position_continuous() 不同。普通 ggplot2 注释应使用 位置映射,不能把 bp 直接当作笛卡尔 x/y。
完成后检查
先检查区间与链,再看形状与标签。未知链仍保留在通用注释中;堆叠改变显示位置,不改变原始基因组坐标。