Circlize 错误:由于 `gap. Degree` 参数的长度大于 1,因此它的长度应与扇区数相同

问题描述 投票:0回答:1

我想使用 circlize 库绘制和弦图。

gap.degree
参数定义为两个相邻扇区之间的间隙。它可以是单个值或向量。如果它是一个向量,第一个值对应于第一个扇区之后的间隙。

library(circlize)

split <- clin.info$subtype
levels <- as.factor(c("1a","1b","1c","2a","2b","2c"))
split <- factor(split, levels=levels)
meth.col <- colorRamp2(c(-2, 0, 2), c("#2f4b7c", "white", "#ffa2ab"))

chordDiagram(meth, split=split, col=meth.col)

追溯:

Error: Since `gap.degree` parameter has length larger than 1, it should have same
length as the number of sectors.

在 github 存储库中,错误是从以下位置引发的:

if(length(gap.degree) == 1) {
    gap.degree = rep(gap.degree, n.sector)
} else if(length(gap.degree) != n.sector) {
    stop_wrap("Since `gap.degree` parameter has length larger than 1, it should have same length as the number of sectors.")
}

但是,即使我设置了

gap.degree=length(levels)
(即6),我仍然遇到相同的错误。

数据:

> dput(meth[,1:10])
structure(c(0.698400609291698, 0.569616475152962, 0.361663286004057, 
0.894450335807706, 0.903375573519773, 0.859059843307218, 0.940601044067159, 
0.521922873745378, 0.0702138966387671, 0.738057576716229, 0.144308943089431, 
0.964523395105969, 0.313691440919966, 0.0543364071436909, 0.0627827129543844, 
0.971661960467931, 0.49453190722269, 0.652882820940969, 0.790132158590308, 
0.457882228677053, 0.522791070712472, 0.851505819719192, 0.5001145883731, 
0.738021999655486, 0.537596430895065, 0.120295281760689, 0.472352424198037, 
0.727940124898699, 0.487917711991972, 0.569710508599057, 0.937831740976645, 
0.35166041533254, 0.487718812703245, 0.541259958845565, 0.331156061244557, 
0.203590017349526, 0.550081662355945, 0.450976691516467, 0.573303889093363, 
0.790762216275151, 0.688423092994612, 0.590548915449314, 0.932058544251989, 
0.191923990498812, 0.593854171886745, 0.950431661654865, 0.609003405893677, 
0.659275506357312, 0.855020236181183, 0.530707519376331, 0.151359885608746, 
0.924031174031174, 0.554841926212681, 0.912106415221418, 0.862858514780268, 
0.654907812000426, 0.658774373259053, 0.598172551607817, 0.621863279679009, 
0.530997030984343, 0.901532994504359, 0.32514014661492, 0.219651551120589, 
0.466090851403104, 0.153084790498185, 0.840072012602205, 0.593664247819989, 
0.424964813511612, 0.0719749938307148, 0.929303517353832, 0.433888888888889, 
0.316858798802624, 0.58567587386947, 0.836810164991466, 0.642473555736371, 
0.858630054315027, 0.695893627824321, 0.831358597249134, 0.915266651407645, 
0.419448056639214, 0.065347291935561, 0.730586300395608, 0.0837818003913894, 
0.644707132421304, 0.477677820749958, 0.384334656265681, 0.0760414470612111, 
0.965555555555556, 0.36985112954159, 0.890470809792844, 0.819155774587529, 
0.820853743876837, 0.340328697850822, 0.645810136130168, 0.649046982369951, 
0.829524363555777, 0.951936083868786, 0.0692403581007064, 0.180922437166386, 
0.732900207900208, 0.310904004616741, 0.700932479496686, 0.494150125020185, 
0.674695620091709, 0.548544625072287, 0.96552621308703, 0.417089708544854, 
0.864486545191263, 0.845707519242155, 0.704594935258393, 0.561292790208453, 
0.586482578609857, 0.316413878116413, 0.850021140023831, 0.93549139690872, 
0.300394218134034, 0.078818584835051, 0.561443036059692, 0.0955170449922708, 
0.83359872611465, 0.938921087828801, 0.393268255578093, 0.0541802322009951, 
0.972265467335524, 0.247739913519545, 0.480850710309878, 0.66749047471939, 
0.863841686384169, 0.410055865921788, 0.71101944603253, 0.881297274154417, 
0.663846072073987, 0.923782791752132, 0.416209526809621, 0.262661611742977, 
0.793333710599287, 0.149220724515586, 0.939792677393459, 0.553316305957698, 
0.443336855161009, 0.0853461604535303, 0.957084987767216, 0.559965458832907, 
0.451124490880113, 0.886174347584675, 0.743330349149508, 0.388026607538803, 
0.616506813173169, 0.516293640897756, 0.848031364299204, 0.439970793783248, 
0.115624178033869, 0.72700434397537, 0.872507290627641, 0.6741593303507, 
0.466630364496478, 0.960659826540446, 0.0563967522492868, 0.39722675868832, 
0.436172392596134, 0.357436499779768, 0.81150603980186, 0.877723188279811, 
0.819144668217925, 0.632992811199395, 0.924025457438345, 0.488020050125313, 
0.825291909924937, 0.94776748104465, 0.191419478039465, 0.195826197777689, 
0.797075632746975, 0.6670289266988, 0.680203045685279, 0.804299073329666, 
0.0621802623011813, 0.177256892873538, 0.974247501735954, 0.28614357848861, 
0.765711680218862), dim = c(18L, 10L), dimnames = list(c("cg06145336", 
"cg06271190", "cg07774251", "cg03357952", "cg06803853", "cg09096824", 
"cg04179953", "cg03495084", "cg07300846", "cg09221960", "cg07160932", 
"cg06239131", "cg07512361", "cg05613116", "cg01890845", "cg00111335", 
"cg00425213", "cg09187695"), c("TCGA-Y8-A8S1-01", "TCGA-Y8-A8S0-01", 
"TCGA-Y8-A8RZ-01", "TCGA-Y8-A8RY-01", "TCGA-Y8-A897-01", "TCGA-Y8-A896-01", 
"TCGA-Y8-A895-01", "TCGA-Y8-A894-01", "TCGA-WN-A9G9-01", "TCGA-V9-A7HT-01"
)))

> dput(clin.info[1:10,])
structure(list(subtype = c("2a", "1a", "1b", "1a", "1a", "1b", 
"2b", "2b", "2a", "1a"), age = c("61", "58", "55", "63", "68", 
"62", "74", "57", "55", "67")), class = "data.frame", row.names = c("TCGA-Y8-A8S1-01A", 
"TCGA-Y8-A8S0-01A", "TCGA-Y8-A8RZ-01A", "TCGA-Y8-A8RY-01A", "TCGA-Y8-A897-01A", 
"TCGA-Y8-A896-01A", "TCGA-Y8-A895-01A", "TCGA-Y8-A894-01A", "TCGA-WN-A9G9-01A", 
"TCGA-V9-A7HT-01A"))
r visualization heatmap circlize complexheatmap
1个回答
0
投票

要解决此错误,您必须为每个扇区指定间隙参数。您可以使用

gap.after
函数的
circos.par()
参数来解决此错误。你可以这样使用它:

library(circlize)
circos.clear()
circos.par(gap.after=c(rep(1,length(rownames(meth))-1),10,rep(1,length(colnames(meth))-1),10))
chordDiagram(meth)

要调整标签重叠,您可以使用以下代码:

library(circlize)
circos.clear()
circos.par(gap.after=c(rep(1,length(rownames(meth))-1),10,rep(1,length(colnames(meth))-1),10))
chordDiagram(meth, annotationTrack = "grid", 
         preAllocateTracks = list(track.height = 0.3)
         )
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(CELL_META$xcenter, ylim[1] + cm_h(2),sector.name,
        facing = "clockwise",niceFacing = TRUE, adj = c(0, 0.5))
circos.axis(h = "bottom",labels.cex = .6,sector.index = sector.name)
}, bg.border = NA)

© www.soinside.com 2019 - 2024. All rights reserved.