跳到正文
0.16.6 文档

本页完整说明已译为现代汉语;函数、参数、代码和原始数据标识保留原样。 使用教程

全站目录 · 按任务查找

色块与柱要求 accver、start、end;线要求 accver、pos。track_value 映射数值高度,track_fill 或 track_colour 映射视觉属性,不由列名推断数值。group 区分折线系列,同一序列/系列的位置须严格递增。NA 高度断开线或省略柱,不当作零;拒绝 Inf。色块可按输入顺序重叠,不平均、插值或隐式聚合。

用法

代码
geom_track_tile(
  mapping = NULL,
  data = NULL,
  position,
  fill = "#86AFB9",
  colour = NA,
  alpha = 1,
  linewidth = 0.25,
  linetype = 1,
  bounds = c("error", "clip"),
  show.legend = NA,
  inherit.aes = FALSE,
  ...
)

geom_track_line(
  mapping = NULL,
  data = NULL,
  position,
  colour = "#387D88",
  alpha = 1,
  linewidth = 0.4,
  linetype = 1,
  closed = FALSE,
  bounds = c("error", "clip"),
  show.legend = NA,
  inherit.aes = FALSE,
  ...
)

geom_track_bar(
  mapping = NULL,
  data = NULL,
  position,
  baseline = 0,
  fill = "#86AFB9",
  colour = NA,
  alpha = 1,
  linewidth = 0.25,
  linetype = 1,
  bounds = c("error", "clip"),
  show.legend = NA,
  inherit.aes = FALSE,
  ...
)

参数

mapping, data

标准 ggplot2 映射与图层输入。

position

每层必须提供 position_track() 声明。

fill, colour, alpha, linewidth, linetype

固定样式;填色和颜色映射使用专用轨道角色及作用域标度。

bounds

基因组坐标策略为 "error"(默认)或 "clip"。裁剪会报告,不改变源值。

show.legend, inherit.aes

标准图层参数。

...

其他几何参数。

closed

是否显式闭合完整圆形折线。

baseline

显式数值柱基线,默认零;参与标度训练,须在限制/变换下仍可表达。

返回值

具有独立输入及共享命名带的 ggplot2 图层。

详细说明

坐标均为窗口局部一基闭区间。区间箱占据完整 end - start + 1 碱基,包括单碱基箱;折线使用指定位置不分箱。源窗口使用 focus_ggchord_track()。不连接不同窗口,即使共享显示行;圆形折线仅在显式 closed = TRUE 时闭合,不跨 NA 连接缺失端点。

示例

代码
library(ggchord)
library(dplyr)
data(plasmid_example_pUC19)
track_seq <- plasmid_example_pUC19 |>
  select(accver, length)
starts <- seq.int(1L, track_seq$length, by = 100L)
gc_fraction <- function(sequence) {
  bases <- strsplit(sequence, "")[[1]]
  mean(bases %in% c("G", "C"))
}
bins <- tibble(
  accver = track_seq$accver,
  start = starts,
  end = pmin(starts + 99L, track_seq$length)
) |>
  rowwise() |>
  mutate(gc = gc_fraction(substr(plasmid_example_pUC19$sequence, start, end))) |>
  ungroup()
doc_theme <- theme_ggchord_publication(
  axis.text = element_text(size = 9), axis.text.check.overlap = TRUE
) +
  theme(legend.position = "bottom")
p_tracks <- ggchord(seq_data = track_seq) +
  geom_seq() +
  geom_seq_center_label() +
  geom_track_bar(aes(track_value = gc, track_fill = gc),
    data = bins,
    position = position_track("gc", width = unit(6, "mm"))
  ) +
  scale_track_value_continuous("gc", limits = c(0, 1), unit = "GC fraction") +
  scale_track_fill_gradientn("gc", colours = c("#EDF1EA", "#8AAE9C", "#345F58")) +
  coord_circular() +
  doc_theme