R circlize 包:文本绘图问题

问题描述

我无法理解为什么我无法使用 circlize 包在 R 中手动向我的 circos 图中添加文本。

(我的主要目标是使用 circlize 来说明使用自定义代码的圆形基因组中的基因顺序。我知道有绘制基因组的函数,但我想制作自己的管道。)

我根据提供的示例 here(第 1.2 节“快速浏览”)为我的代码建模。

基本上,我首先绘制第一个轨道中的扇区(这里是基因)。在第一个轨道中,只有 2 个扇区应该被着色(红色和橙色);其余的应该是灰色的。然后我尝试将文本标签(扇区/基因名称添加到这些彩色扇区,但我得到了错误

Error: 'circos.text' can only be used after the plotting region been created.

感谢帮助!并提前致谢。 :3

~ jat

这是说明我的问题的代码

library(circlize); library(data.table); library(tidyverse)
circos.clear()

# Dummy data.table to test colours for different tracks (1 or 2) for 
# different genes and strands.
chromDT <- data.table(
  gene=LETTERS[1:6],strand=c('+','+','-','-'),end=c(10,25,50,55,100,2),ht1=c(0.1,0.1,0.05,0.05),ht2=c(0.05,0.1),col1=c('red','orange','grey50','grey50'),col2=c('grey50','green','blue','purple','hotpink')
)

# Circle margins
circ_marg <- c(0.5,0.5,0.5)

# Genes on the plus and negative strand,as vector
genes_plus <- chromDT[strand=='+']$gene
genes_neg <- chromDT[strand=='-']$gene

# Plot space parameters
circos.par(
  gap.degree=0,track.margin=c(0,0),cell.padding=c(0.005,1,0.005,1),circle.margin=circ_marg
)

# Matrix of x limits per sector
xMat <- cbind(rep(0,6),chromDT$end)
rownames(xMat) <- chromDT$gene

# Intialise
circos.initialize(chromDT$gene,xlim=xMat)

# Track 1 genes (sectors)
circos.track(
  ylim=c(0,bg.col=chromDT$col1,bg.border = 'grey50',track.height=0.15,)

# Plotting gene (sector) labels - throws error. :(
circos.text(
  x=xMat[genes_plus,] %>% apply(.,mean),y=rep(1,length(genes_plus)),labels= genes_plus,track.index = 1,sector.index = genes_plus,)

这是图像输出(遗憾的是没有标签!):

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)