14

这是circlize包中用于创建和弦图的一些代码。现在标签与圆的边缘平行。是否可以将标签旋转 90 度使其垂直于圆?

library(circlize)
set.seed(999)
mat = matrix(sample(18, 18), 3, 6)
rownames(mat) = paste0("Start", 1:3)
colnames(mat) = paste0("End", 1:6)
chordDiagram(mat)

在下图中,我手动插入了一些标签来显示我希望完成的任务(End5、End6、End7​​)。谢谢。

在此处输入图像描述

4

1 回答 1

14

根据您的示例数据,这是一种方法:

grid.col <- setNames(rainbow(length(unlist(dimnames(mat)))), union(rownames(mat), colnames(mat)))
par(mar = c(0, 0, 0, 0), mfrow = c(1, 2))

# original image
chordDiagram(mat, grid.col = grid.col) 

# now, the image with rotated labels
chordDiagram(mat, annotationTrack = "grid", preAllocateTracks = 1, grid.col = grid.col)
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, 0.5))
  circos.axis(h = "top", labels.cex = 0.5, major.tick.percentage = 0.2, sector.index = sector.name, track.index = 2)
}, bg.border = NA)

结果:

在此处输入图像描述

于 2015-08-11T20:39:45.090 回答