increasing the distance between igraph nodes

社会主义新天地 提交于 2019-11-30 02:14:15

问题


I have a graph that I have produced using igraph. I'd like to spread out the nodes. The only way I have found so far to do this is to scale the layout and force the plot command to not rescale.

png("kmeansColouredNetwork.png", width=1200,height = 1000)
col=c("yellow", "saddlebrown", "brown1","chartreuse2", "chocolate1","darkorange" ,"deepskyblue1", "hotpink1","plum2")
for(i in 1:9){
  V(graph)$cluster[which(V(graph)$name %in% kmeans[,i])]<-col[i]
}
V(graph)$color=V(graph)$cluster
coords <- layout.fruchterman.reingold(graph)*0.5
plot(graph, layout = coords, vertex.label=NA, rescale=FALSE,  vertex.size=degree(graph)*.25,vertex.color=V(graph)$cluster)
labels = paste("cluster:", 1:length(colours))
legend("left",legend=labels, col=col, pch=16, title="K means clustered subgroups")
dev.off()

If I don't rescale, the central highly connected nodes clump together and I get a graph like this, where the patterns in the body of the graph are impossible to discern:

On the other hand, if I tell the plot command not to rescale, then I get this :

where the patterns are discernible, but half the graph is off the plot. It's not a matter of plot size as if I increase the dimensions of the png, it still centres the graph off the edge of the plot.

It's not a matter of the layout - I've tried fruchterman.reingold, layout_nicely, reingold.tilford, layout.circle, layout random, the same thing happens.

There apparently used to be a variable to set a repulsion factor between nodes, but that appears to be deprecated.

How does one spread the nodes of the graph out or rescale and recenter the plot?


回答1:


It is NOT my answer, just found on stackoverflow:
igraph axes xlim ylim plot incorrectly

Basically, you can set ylim and xlim and asp. You can set which part of the graph to display (as usual with xlim and ylim) and if the two axis are dependent on each other.

plot(g, rescale = FALSE, ylim=c(1,4),xlim=c(-17,24), asp = 0)



回答2:


Option 1: make the vertices smaller

node.size= c(10,10,10)
plot(net, vertex.size=node.size*0.25)

Option 2 (in case the distances between the vertices are not important to you):

# Use the tkplot option to edit your graph in GUI
tkplot (net)

Note: tkplot outputs the graph as eps. If you want to edit it further or export it to pdf I suggest using inkscape (I use it for all my graph editing - just save the graph as pdf in RStudio and edit it in inkscape). For the case of eps if you are on a windows machine you will need to tweak inkscape to open this format. A very short and simple process which is detailed here:



来源:https://stackoverflow.com/questions/32857024/increasing-the-distance-between-igraph-nodes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!