我正在使用此帖子中的代码:R igraph程序包中树形图条目的顺序不正确
如果标签全部/大部分为数字,则该代码不起作用:
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
>
代码中的'edges'数据框已正确设置(我检查了print(edges))。我怎么解决这个问题?谢谢你的帮助。
我会将其写为注释,但这不允许结构化代码。作为标签的数字在igraph中可以正常工作:
library(igraph)
g <- graph.ring(9)
V(g)$label <- as.character(seq(111, 999, by=111))
plot(g)
也许您要添加顶点名称,而不是将其转换为字符?如果将顶点指定为数字(即mode numeric
),则igraph会将其视为数字顶点ID,而不是符号顶点名称。
无论如何,无论您想用作绘图的标签,将其分配为label
顶点属性。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句