我正在使用 R 中的 Chord Diagrams(通过 Circlize/Circos 包)来可视化数据集中的名称关联。我能够生成和弦图(如下所示):
但是,我不知道如何根据其各自的宽度对每个扇区(或每个名称)进行排序(例如:在和弦图的下半部分,我想像这样按降序排列扇区:N/A将被放在第一位,然后是 Dean、Aaron、Malcolm、... Jay)。是否有特定的 circos 功能可以让我这样做?
这是我的代码:
library(circlize)
setwd("C:/Users/Main/Desktop/")
data <- read.table('./r_test.txt',header = FALSE,sep = '\t')
chordDiagram(data,annotationTrack="grid",grid.col =
c("springgreen","coral","indianred","violet",
"greenyellow","cyan","purple","firebrick",
"gold","darkblue","red","magenta",
"orangered","brown","blueviolet","darkgoldenrod",
"aquamarine","khaki"),preAllocateTracks=list(track.height = link.sort =
TRUE,link.decreasing = TRUE)
circos.trackPlotRegion(track.index = 1, panel.fun = function(x, y) {
xlim = get.cell.meta.data("xlim")
xplot = get.cell.meta.data("xplot")
ylim = get.cell.meta.data("ylim")
sector.name = get.cell.meta.data("sector.index")
circos.text(mean(xlim), ylim[1], sector.name, facing = " niceFacing = TRUE,
adj = c(0, .75),cex=2)
},bg.border = NA)
数据文件是一个制表符描述的 .txt 文件,前 2 列中有名称(每列有 10 个名称,列中有“Other”和“N/A”;第三列是频率计数)。