我有一个相当复杂的马戏团情节,并且在对齐标签时遇到了一些麻烦。
为了演示这个问题,我在下面提供了一个简短的可重现示例。
我无法弄清楚如何很好地对齐每个标签,以便它们与相应的段的距离完全相同,例如根据标签 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)