R circlize:circos.initialize中的错误 [英] R circlize: Error in circos.initialize

查看:154
本文介绍了R circlize:circos.initialize中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CRAN上的软件包说明中,我能够轻松遵循Circlize示例:

I am able to follow the Circlize example in the description of the package on CRAN easily:

library('circlize')
set.seed(123)
mat = matrix(sample(1:100, 18, replace = TRUE), 3, 6)
rownames(mat) = letters[1:3]
colnames(mat) = LETTERS[1:6]
### basic settings
par(mfrow = c(3, 2))
par(mar = c(1, 1, 1, 1))
chordDiagram(mat)

但是,当我将mat替换为myMatrix时,会出现此错误:

however, when I replace mat with myMatrix I get this error:

Error in circos.initialize(factors = factor(cate, levels = cate), xlim = cbind(rep(0,  : 
  Since `xlim` is a matrix, it should have same number of rows as the length of the level of `factors` and number of columns of 2.

有人可以解释为什么我收到该消息吗?除了myMatrix之外,我看不到matmyMatrix之间的差异更大:

Can somebody explain why I am getting that message? I do not see a difference between mat and myMatrix other than myMatrix is larger:

    A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z   A2  B2  C2  D2
A   1060360.659 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
B   0   32143148.75 996976.8445 0   4944648.524 5688385.041 61990.5913  0   0   0   0   -1563.225   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   31922242.6
C   0   0   6342776.843 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
D   0   0   0   28617385.81 17842142.64 0   0   0   0   0   0   0   0   409444.5633 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
E   0   0   0   4990921.202 105686446.3 536246.2188 0   0   0   0   0   0   0   8587899.583 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   378565.5746
F   0   92732.7741  0   4282.9319   33543553.89 36773976.59 1894761.93  0   0   333209.342  0   20739.0655  327956.7365 0   1022673.163 12229.0255  0   0   386112.1743 224039.3207 0   2395066.197 268247.2897 0   0   0   0   0   0   11926701.96
G   0   0   0   0   0   0   7753767.003 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
H   0   0   0   0   0   5184133.29  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
I   0   0   0   0   462767.7374 0   0   0   8992223.296 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
J   0   0   0   0   0   0   0   0   0   1950552.642 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
K   0   0   0   0   891032.5584 0   0   0   0   0   520107.9821 0   0   0   0   0   0   0   0   0   0   0   0   0   0   26724.8402  0   0   0   418902.5203
L   0   0   0   0   32044317.54 28147.5693  0   0   0   0   0   5383919.293 0   489912.5412 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   4559115.003
M   0   0   0   0   0   3125823.41  0   0   0   0   0   0   1738293.164 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
N   0   1053825.966 -8526.9758  1283429.314 60333051.34 2621812.931 -1130.1924  0   -779545.8004    8055145.684 918.8702    -379747.1919    -177.6205   298563606.5 -9316.8654  0   0   0   0   0   2631991.077 0   0   0   0   0   1107369.803 0   0   118812465
O   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1500451.292 0   0   0   0   0   0   0   0   0   0   0   0   0   0   7432418.396
P   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
Q   0   0   1496058.76  0   -4056617.74 294503  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   410.4   0   0   0   0   0   0   0   1765984767

代码

dd <- read.table(header = TRUE, text = "  rn  A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z   A2  B2  C2  D2
A   1060360.659 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                 B   0   32143148.75 996976.8445 0   4944648.524 5688385.041 61990.5913  0   0   0   0   -1563.225   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   31922242.6
                 C   0   0   6342776.843 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                 D   0   0   0   28617385.81 17842142.64 0   0   0   0   0   0   0   0   409444.5633 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                 E   0   0   0   4990921.202 105686446.3 536246.2188 0   0   0   0   0   0   0   8587899.583 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   378565.5746
                 F   0   92732.7741  0   4282.9319   33543553.89 36773976.59 1894761.93  0   0   333209.342  0   20739.0655  327956.7365 0   1022673.163 12229.0255  0   0   386112.1743 224039.3207 0   2395066.197 268247.2897 0   0   0   0   0   0   11926701.96
                 G   0   0   0   0   0   0   7753767.003 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                 H   0   0   0   0   0   5184133.29  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                 I   0   0   0   0   462767.7374 0   0   0   8992223.296 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                 J   0   0   0   0   0   0   0   0   0   1950552.642 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                 K   0   0   0   0   891032.5584 0   0   0   0   0   520107.9821 0   0   0   0   0   0   0   0   0   0   0   0   0   0   26724.8402  0   0   0   418902.5203
                 L   0   0   0   0   32044317.54 28147.5693  0   0   0   0   0   5383919.293 0   489912.5412 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   4559115.003
                 M   0   0   0   0   0   3125823.41  0   0   0   0   0   0   1738293.164 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                 N   0   1053825.966 -8526.9758  1283429.314 60333051.34 2621812.931 -1130.1924  0   -779545.8004    8055145.684 918.8702    -379747.1919    -177.6205   298563606.5 -9316.8654  0   0   0   0   0   2631991.077 0   0   0   0   0   1107369.803 0   0   118812465
                 O   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1500451.292 0   0   0   0   0   0   0   0   0   0   0   0   0   0   7432418.396
                 P   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                 Q   0   0   1496058.76  0   -4056617.74 294503  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   410.4   0   0   0   0   0   0   0   1765984767")

myMatrix <- as.matrix(dd[, -1])
rownames(myMatrix) <- dd[, 1]
chordDiagram(myMatrix)

推荐答案

在旧版本的 circlize 中,矩阵必须是matrix类而不是data.frame,因此您需要通过以下方式显式转换数据帧:

In the old version of circlize, the matrix must be of a matrix class instead of a data.frame, so you need to convert the data frame explicitly by:

myMatrix = as.matrix(A + B)

在循环中,数据帧用于存储作为邻接表的数据(例如,第一列用于组1,第二列用于组2,第三列用于关系的强度).

In circlize, a data frame is for data stored as a adjacency list (e.g the first column for group1, second column for group2, third column for the strength of the relation).

由于read.table()始终返回data.frame类,因此在较新版本的circlize中,将矩阵表示为数据帧就可以了.当它是数据帧时,chordDiagram()将首先检查列数是否大于3,并且所有列都是数字.如果是这样,它将在内部转换为矩阵.

Since read.table() always returns a data.frame class, in the newer version of circlize, it is fine if the matrix represents as a data frame. When it is a data frame, the chordDiagram() will first check whether the number of columns is larger than 3 and all columns are numeric. If so, it will be converted to a matrix internally.

这篇关于R circlize:circos.initialize中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆