igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] Layout of nodes in a 2D graph with fixed Y-positions and random


From: Charles Novaes de Santana
Subject: [igraph] Layout of nodes in a 2D graph with fixed Y-positions and random non-overlapping X-positions
Date: Tue, 26 Jan 2016 17:08:13 +0100

Dear all,

Does any of you have an idea about how to automatically generate a layout for a 2D graph considering that:

1 - the user gives the Y-position of the nodes
2 - the user don't care about the X-position of the nodes
3 - the nodes can have different sizes
4 - the nodes can not overlap
5 - the nodes should show their numeric labels, preferably inside them

I was planning to do this by myself, creating the X-positions according to the number of nodes in each "level" of the graph and to the maximum size of a node. And I decided to write to the list just to see if anyone have implemented it before and could help me.

Please consider the code below as a starting point:

```
library(igraph)

nnodes = 100;#number of nodes is 100
g<-erdos.renyi.game(nnodes,0.07);#random graph with nnodes nodes
ypos<-round(runif(nnodes,min=0,max=3))#positions between 0 and 10
mysizes<-runif(nnodes,min=8,max=16)#sizes between 3 and 10
xpos<-runif(nnodes)
mylayout<-as.matrix(cbind(xpos,ypos))

png("./test.png",width=1980,height=1240,res=100)
plot(g, layout=mylayout, vertex.size=sizes, axes = FALSE, rescale=FALSE, ylim=range(ypos), vertex.size=mysizes)
dev.off();
```
The resulting figure is here

Any suggestion about how to define the vector xpos in such a way that I can avoid nodes to overlap? Any other suggestion to create the layout?

Thanks for any help!

Charles

--
Um axé! :)

--
Charles Novaes de Santana, PhD
https://github.com/cndesantana

reply via email to

[Prev in Thread] Current Thread [Next in Thread]