难以使用igraph和networkd3生成有向图

时间:2017-02-23 09:30:24

标签: r igraph networkd3

我有一个xlsx包含大约2000多个节点和9000个边缘。我想生成一个明确的有向图。我在R中尝试了igraph包来生成我想要的有向图,但是(1)它是太多的节点和边缘打印清楚。我参考一些文件,使用networkd3将igraph转换为networkd3和绘图,但(2)方向(箭头)输了。 你能帮我解决这些情况吗? (1)或(2)。我的代码在下面,我的数据格式如 edges1.xlsx 源目标attr s1 s2 a s2 s7 b s2 s3 c

nodes1.xlsx id attr s1 a s2 c s3 d s4 c

library(readxl)
library(igraph)
links <- read_excel("C:\\Users\\file\\Desktop\\1W\\edges1.xlsx",sheet=1,col_names = TRUE)
nodes <- read_excel("C:\\Users\\file\\Desktop\\1W\\nodes1.xlsx",sheet=1,col_names = TRUE)
net   <- graph_from_data_frame(d=links,vertices=unique(nodes$JYZH),directed = T)
plot(net, vertex.color="orange",vertex.size=.1,vertex.label=NA,vertex.label.color="black",vertex.label.dist=0,edge.arrow.size=.01)
#above work well with my data format but because it is too many nodes(2000+) and edges(9000+) to print clearly
library(networkD3)

#Use igraph to make the graph and find membership
wc <- cluster_walktrap(net)
members <- membership(wc)

#Convert to object suitable for networkD3
net_d3  <- igraph_to_networkD3(net,group = members)
forceNetwork(Links = net_d3$links, Nodes = net_d3$nodes,
         Source = 'source', Target = 'target', NodeID = 'name',Group = 'group', zoom = TRUE)
#using above code of networkd3,the direction lost.....

有没有解决这些问题的解决方案?

1 个答案:

答案 0 :(得分:2)

  1. 无论您使用哪种软件生成它,具有2000多个节点和9000条边的网络图都会变得混乱。如果你用networkD3绘制它,你希望会有什么不同?

  2. 更新(2017.03.24):此功能(使用箭头显示边/链接的方向)位于networkD3的最新发布版本(0.4)中,{{ 1}} arrows = TRUE的参数。