visNetwork icon indicating copy to clipboard operation
visNetwork copied to clipboard

Physics layout for rectangular (non 1:1 aspect ratio) canvas

Open sneumann opened this issue 5 years ago • 7 comments

Hi, I'd like a visualisation of a medium-sized network (~100 nodes) with ~7 disconnected subcomponents, and have a standard visNetwork() with standard visPhysics() and standard visLayout(). The resulting network after a while settles into a square-ish shape, i.e. 1:1 aspect ratio.

For publication I want a wide layout, but setting visNetwork(width = xxx, height = yyy) just changes the canvas. I guess what I am looking for is to extend centralGravity to have different gravity in x and y dimensions. Maybe using non-euclidean distance (mahalanobis ?) for the force calculations.

Did I miss something obvious ? I am also happy to use visIgraphLayout() if there is a way to pass the desired aspect ratio.

Thanks in advance, yours, Steffen

sneumann avatar Jul 23 '19 08:07 sneumann

hi sneumann have you found a solution to coerce the aspect ratio of the clusters into a non-square? I run into the same spot too.

terenceltl avatar Feb 26 '20 07:02 terenceltl

Hi, afraid I don't think so. Our visualisation code is in https://github.com/rformassspectrometry/metaRbolomics-book/blob/master/rmd/99-Appendices/9902-Appendices-Appendix_2_metaRbolomics_dependencies.Rmd#L120 and the results in https://rformassspectrometry.github.io/metaRbolomics-book/9902-Appendices-Appendix_2_metaRbolomics_dependencies.html and it is still square. Any suggestions still welcome. Yours, Steffen

sneumann avatar Feb 26 '20 10:02 sneumann

adding the following line kinda works for me:

visIgraphLayout(type="full", randomSeed = 999)

if you want physics effect:

visIgraphLayout(physics = T, type="full", randomSeed = 999)

and you may have to further tune the gravity, and for my case I have to trial and error for the optimal value:

visPhysics(solver = "barnesHut", barnesHut = list(gravitationalConstant = -2700))

terenceltl avatar Feb 26 '20 12:02 terenceltl

#Steffen, so does my suggestions work in your case?

So far I find that it is a pain to control the layout of nodes.

terenceltl avatar Feb 29 '20 23:02 terenceltl

Hi, I'd like a visualisation of a medium-sized network (~100 nodes) with ~7 disconnected subcomponents, and have a standard visNetwork() with standard visPhysics() and standard visLayout(). The resulting network after a while settles into a square-ish shape, i.e. 1:1 aspect ratio.

For publication I want a wide layout, but setting visNetwork(width = xxx, height = yyy) just changes the canvas. I guess what I am looking for is to extend centralGravity to have different gravity in x and y dimensions. Maybe using non-euclidean distance (mahalanobis ?) for the force calculations.

Did I miss something obvious ? I am also happy to use visIgraphLayout() if there is a way to pass the desired aspect ratio.

Thanks in advance, yours, Steffen

Multiple gravity centers, possibly allowing "drag and drop" gravity centers would be absolutely great!

renanxcortes avatar Apr 21 '20 01:04 renanxcortes

adding the following line kinda works for me:

visIgraphLayout(type="full", randomSeed = 999)

if you want physics effect:

visIgraphLayout(physics = T, type="full", randomSeed = 999)

and you may have to further tune the gravity, and for my case I have to trial and error for the optimal value:

visPhysics(solver = "barnesHut", barnesHut = list(gravitationalConstant = -2700))

I tried this workaround in my use cases, however, it was not enough for the networks I'm generating :(

renanxcortes avatar Apr 21 '20 11:04 renanxcortes

In my use case, I think i managed to spread things out horizontally a bit more by supplying a start matrix with x/y coordinates for each node. Hard to tell though since the physics takes over after this:

 start <- data.table::as.data.table(g)[,list(x=ifelse(group=="group1",
                                                         -100,100),
                                                y=0)] |> as.matrix()
 visNetwork::visIgraphLayout(layout = "layout_with_graphopt",
                                    type = "full",
                                    start = start)
Screenshot 2023-04-17 at 02 01 09

bschilder avatar Apr 17 '23 01:04 bschilder