I'm using Chord Diagrams in R (via the Circlize/Circos packages) to visual name associations in a dataset. I was able to generate the Chord Diagram (as shown below):
However, I don't know how to sort each sector (or each name) based on its respective width (e.g.: In the lower half of the Chord Diagram, I would like to arrange the sectors in descending order like this: N/A would be placed first, followed by Dean, Aaron, Malcolm, ... Jay). Is there a specific circos function that would allow me to do this?
Here's my code:
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)
The data file is a tab-delineated .txt file with names in the first 2 columns (there are 10 names in each column along with "Other" and "N/A" in the columns; the third column is a frequency count).