简体   繁体   中英

R: Sorting Sectors in Chord Diagram based on Width?

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 (eg: 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).

Depends on the order of the data you inputted.

Do data[order,] and do the same thing, where order = a vector of the names in the order that you'd like.

Here is a very useful resource that I have used: https://jokergoo.github.io/circlize_book/book/the-chorddiagram-function.html

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM