R中的igraph不使用数字标签

时间:2014-07-25 08:10:33

标签: r igraph

我正在使用此帖子中的代码:Order of treechart entries not correct in R igraph package

如果标签全部/主要是数字,则代码不起作用:

111
    222
    333
        99
        1010
    44
    55
    66
        1111
            1313
            1414
            1515
    77
    88
        1212

以下是错误:

Error in if (vr[1] == vr[2]) { : missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In mean.default(sapply(nb, function(x) calcypos(g, x))) :
  argument is not numeric or logical: returning NA
2: In mean.default(sapply(nb, function(x) calcypos(g, x))) :
  argument is not numeric or logical: returning NA
3: In mean.default(sapply(nb, function(x) calcypos(g, x))) :
  argument is not numeric or logical: returning NA
4: In mean.default(sapply(nb, function(x) calcypos(g, x))) :
  argument is not numeric or logical: returning NA
5: In mean.default(sapply(nb, function(x) calcypos(g, x))) :
  argument is not numeric or logical: returning NA
6: In mean.default(sapply(nb, function(x) calcypos(g, x))) :
  argument is not numeric or logical: returning NA
7: In mean.default(sapply(nb, function(x) calcypos(g, x))) :
  argument is not numeric or logical: returning NA
8: In mean.default(sapply(nb, function(x) calcypos(g, x))) :
  argument is not numeric or logical: returning NA
9: In mean.default(sapply(nb, function(x) calcypos(g, x))) :
  argument is not numeric or logical: returning NA
10: In mean.default(sapply(nb, function(x) calcypos(g, x))) :
  argument is not numeric or logical: returning NA
> 

代码中的'edge'数据框正常(我用print(边缘)检查)。 我怎么解决这个问题?谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

我会把它写成评论,但这不允许结构化代码。作为标签的数字在igraph中运行良好:

library(igraph)
g <- graph.ring(9)
V(g)$label <- as.character(seq(111, 999, by=111))
plot(g)

enter image description here

也许您正在添加顶点名称,而不是将它们转换为字符?你将顶点指定为数字(即模式numeric),然后igraph将它们视为数字顶点id,而不是符号顶点名称。

无论如何,无论您想用作绘图的标签,都要将其指定为label顶点属性。