2015-08-26 119 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中的布局。