R igraph顶点间距

标签 r igraph

我正在使用 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()

目前,这会将大多数节点绘制为独立点,但有些节点会相互叠加绘制。有没有办法让节点有更好的间距? 谢谢。

最佳答案

我对 igraph 有同样的问题,这些算法提供的布局似乎不能防止节点重叠。

有人可能会想出一个好的 igraph-only 解决方案,但我目前非常乏味的解决方法是:我在 Gephi 上打开网络,然后我使用 Force Atlas 2 算法并选中“防止重叠”选项,我保存.gexf 文件,然后我从文件中提取 xyz 坐标,然后将其用作 igraph 中的布局.

关于R igraph顶点间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32230789/

相关文章:

r - 当 RMarkdown 中的 eval=FALSE 时禁止注释 (#)

r - 使用 R,一次循环两个文件

r - 删除 R 中的节点并固定图形的布局

r - 在 ggplot2 中刻面时添加功能区

r - 如何将工作表名称作为变量添加到我的数据框中

r - 将节点集合的邻居名称提取为列表

r - 在igraph中使用write.graph输出一个.net文件

r - 在 R igraph 中统计网络中连接最多的节点

r - 选择包含特定叶子的子图(igraph)

r - 通过范围内的成员资格将一个数据框连接到另一个数据框