我有一个相当复杂的circos图,在对齐标签时遇到了一些问题。
为了演示这个问题,我在下面提供了一个简短的可重现的示例。
我想不出如何很好地对齐每个标签,使它们与相应片段的距离完全相同,例如,根据标签tyranosauras rex。许多标签都是隐藏和重叠的,并且与绘图边缘的距离不同。任何帮助都将不胜感激。
library("circlize")
circos.clear()
# create data
somelongnames <- c("homo sapiens", "arabidopsis thaliania", "Tyrannosaurus rex",
"some other long name", letters[seq(4)])
df <- data.frame(x = somelongnames,
y = c("this label is very far away from the plot", "Golgi",
letters[13:18]),
count = c(2, 10, 4, 5, 5, 1, 9, 3))
# set colours
ll <- unique(c(df$x, df$y))
grid.col <- rainbow(length(ll))
grid.col <- setNames(grid.col, ll)
# create plot
par(mar = c(1,1,1,1)*12, cex = 0.6, xpd=NA)
chordDiagram(df, annotationTrack = "grid",
preAllocateTracks = 1,
grid.col = grid.col,
directional = 1,
direction.type = c("diffHeight", "arrows"),
link.arr.type = "big.arrow")
circos.trackPlotRegion(track.index = 1, panel.fun = function(x, y) {
xlim = get.cell.meta.data("xlim")
ylim = get.cell.meta.data("ylim")
sector.name = get.cell.meta.data("sector.index")
circos.text(mean(xlim),
ylim[1] + .1,
sector.name,
facing = "clockwise",
niceFacing = TRUE,
adj = c(-0.5, 0.1),
cex = 1,
col=grid.col[sector.name],
font = 2)
circos.axis(h = "top",
labels.cex = .6,
major.tick.length = 1,
sector.index = sector.name,
track.index = 2)
}, bg.border = NA)

发布于 2021-08-17 15:52:35
这个问题已经answered here by the package author of circlize了
在这里重新发布,以回答上述问题-
主要的问题是circos.axis()中track.index = 2的设置改变了当前的曲目。
将y轴上的位置更改为ylim[1] + cm_h(2)。这意味着y = ylim[1]的偏移量为2 2cm。(在绘图上看起来并不是真正的2厘米,但您可以手动更改此值)。adj更改为adj = c(0, 0.5)。请注意,adj的值乘以文本长度的长度,因此所有扇区名称的物理长度都不相同。删除major.tick.length = 1,因为我认为记号的默认长度看起来应该没问题。
下面的代码解决了上面的问题
chordDiagram(df, annotationTrack = "grid",
preAllocateTracks = 1,
grid.col = grid.col,
directional = 1,
direction.type = c("diffHeight", "arrows"),
link.arr.type = "big.arrow")
circos.trackPlotRegion(track.index = 1, panel.fun = function(x, y) {
xlim = get.cell.meta.data("xlim")
ylim = get.cell.meta.data("ylim")
sector.name = get.cell.meta.data("sector.index")
circos.text(CELL_META$xcenter,
ylim[1] + cm_h(2),
sector.name,
facing = "clockwise",
niceFacing = TRUE,
adj = c(0, 0.5),
cex = 1,
col=grid.col[sector.name],
font = 2)
circos.axis(h = "bottom",
labels.cex = .6,
sector.index = sector.name
)
}, bg.border = NA)

https://stackoverflow.com/questions/68482783
复制相似问题