繁体   English   中英

绘制igraph网络像Gephi Force Atlas 2

[英]Plot igraph network like Gephi Force Atlas 2

我有一个具有以下特征的网络(igraph):

>g
IGRAPH DN-- 3370 16699 --
+ attr: name (v/c), grupo (v/n), year (v/n), grupo.freq (v/n),
  grupo.perc (v/n), vertex.frame.size (v/n), color (v/c),
  vertex.frame.color (v/c), grupo (e/n), year (e/n), color (e/c)

make clustering之后有以下组:

>table(V(g)$grupo)
   1    2    8
1516 1367  487

我对可以突出组之间关系的视图感兴趣(V(g)$grupo) 我使用Gephi软件和Force Atlas 2布局到下一张图片: httpGephi

我的问题是,如何在R中得到类似的结果?

我正在使用以下代码:

colbar <- rainbow(length(table(V(g)$grupo)))
V(g)$color <- colbar
E(g)$color <- colbar
V(g)$vertex.frame.color <- colbar
V(g)$vertex.frame.size <- 0.1

plot.igraph(
            g,
            layout=layout.fruchterman.reingold.grid,
            vertex.label=NA,
            vertex.size=1,
            edge.lty=1,
            edge.arrow.size=0.0000001
            )

点击链接下载我在csvRdata使用的数据: httpRdata

现在可以使用R中的代码生成Force Atlas 2布局: https//github.com/adolfoalvarez/Force-Atlas-2

布局尚未开发为包,因此您需要将代码源代码输入到R中,并使用“igraph”包。

用法是:

library(igraph)
g <- graph.ring(100)
layout.forceatlas2(g, iterations=10000, plotstep=500)

首先,获取ForceAtlas2包。

install.packages("devtools")
if (!require("ForceAtlas2")) devtools::install_github("analyxcompany/ForceAtlas2")
library("ForceAtlas2")

然后,渲染图g与布局l这样做(这里所有可用的布局参数):

g <- erdos.renyi.game(1000, 1/1000)
l <- layout.forceatlas2(g, directed=TRUE, iterations = 100, 
                           linlog = FALSE, pos = NULL, nohubs = FALSE, 
                           k = 400, gravity=1, ks=0.1, ksmax=10, delta = 1,  
                           center=NULL, tolerance = 0.1, dim = 2,
                           plotstep=10, plotlabels=TRUE)
plot(g,layout=l)

如果您愿意vertex.size = 3, vertex.color = "red"可以将vertex.size = 3, vertex.color = "red"等选项提供给绘图函数。

现在@ciberalcito提到的ForceAtlas2函数是在R包中实现的。 请查看https://github.com/analyxcompany/ForceAtlas2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM