2015-08-26 142 views
3

我正在使用igraph繪製網絡,並且看起來似乎無法獲取彼此頂部繪製的節點(頂點)。R igraph頂點間距

我的代碼:

g<-graph.empty(n=0, directed=FALSE) 
nodes<-my_verts 
edge<-my_intra_edges 
freq<-nodes[,2] 
max_freq<-sum(freq) 
frequency<-freq*50/max_freq 
colour1<-heat.colors(max_freq/2+2) 
colour<-rev(colour1) 
g<-igraph::add.vertices(g, length(nodes[,2]), name=as.character(nodes[,1]),  color=colour[freq/2+2]) 
names<-V(g)$name 
ids<-1:length(names) 
names(ids)<-names 
from<-as.character(edge[,1]) 
to<-as.character(edge[,2]) 
edges<-matrix(c(ids[from], ids[to]), nc=2) 
my_weight<-edge[,3] 
g<-add.edges(g, t(edges), weight=my_weight) 
V(g)$label<-V(g)$name 
my_radius<-sqrt(my_verts[,2]/pi) 
V(g)$size<-my_radius 
V(g)$label.cex<-0.0001 
del_ids<-intersect(which(degree(g)==0), which(freq==1)) 
g1<-delete.vertices(g, ids[del_ids]) 
length(del_ids) 
jpeg(file="BC9.jpeg", height=7016, width=7016, res=600) 
par(mfrow=c(1,1), mar=c(5,5,5,5)) 
title=c("BC9") 
layout<-layout_with_graphopt(g1, niter=800) 
plot(g1, layout=layout, edge.color="darkblue", main=title, edge.width=0.2) 
dev.off() 

目前這將繪製大部分節點爲獨立點,但一些節點獲得繪製在彼此的頂部。有沒有辦法讓節點有更好的間距? 謝謝。

+1

歡迎來到StackOverflow。如果您提供了最低限度可重複的示例,則您的問題更可能引起關注。例如,你沒有定義'my_verts'或'my_intra_edges',所以你的代碼不會按原樣運行。我建議你[閱讀此](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610)瞭解如何最好地提出問題的一些指針。 – jlhoward

+3

這是一個在屁股疼痛。 [Here](http://stackoverflow.com/questions/32012080/changing-the-spacing-between-vertices-in-igraph-in-r/32013660#32013660)我試圖解決它,但你必須非常努力地工作帶有參數,除非另有用戶提供更好的解決方案。 – SabDeM

回答

1

我有與igraph相同的問題,這些算法提供的佈局似乎並沒有防止節點的重疊。

有人可能會想出一個很好的igraph-only解決方案,但我目前很乏味的解決方法是:我在Gephi上打開網絡,然後使用Force Atlas 2算法並選中「防止重疊」選項保存.gexf文件,然後我從文件中提取x,y,z座標,然後用它作爲igraph中的佈局。