Igraph包R问题与layout_on_grid

时间:2016-06-18 16:15:17

标签: r plot graph igraph

我正在尝试使用layout_on_grid绘制图表并接收消息

  

警告信息:在if(轴){:条件有长度> 1和   只使用第一个元素

它不仅提供警告,而且不应用预期的布局。

这似乎不是图表本身的问题

library(igraph)

rG <- erdos.renyi.game(25,0.2)
plot(rG)

我们可以看到enter image description here

但是布局,警告。

plot(rG, layout_on_grid(rG, dim=2))

我测试了有向和无向边以及带有零或正权重的边。

,布局在这里工作

el <- matrix(nc=3, byrow=TRUE,
             c(1,2,0, 1,3,2, 1,4,1, 2,3,0, 2,5,5, 2,6,2, 5,2,1, 3,4,1,
               3,7,1, 4,3,0, 4,7,2, 5,6,2, 5,8,8, 6,3,2, 6,7,1, 6,9,1,
               6,4,3, 8,6,1, 8,9,1, 7,10,4) )
g <- add_edges(make_empty_graph(10), t(el[,1:2]), weight=el[,3])
plot(g)

plot(g, layout=layout_on_grid(g, width = 4))

enter image description here

我在这里做错了什么想法?

1 个答案:

答案 0 :(得分:2)

plot.igraph的第二个参数是axes。你实际上给它一个矩阵,它想要一个逻辑TRUE / FALSE值。所以它使用了矩阵的第一个值,将其强制转换为布尔值并抛出警告。

添加layout参数后,它将按预期工作:

plot(rG, layout=layout_on_grid(rG, dim=2))