visNetwork
visNetwork copied to clipboard
Physics layout for rectangular (non 1:1 aspect ratio) canvas
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
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.
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
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))
#Steffen, so does my suggestions work in your case?
So far I find that it is a pain to control the layout of nodes.
Hi, I'd like a visualisation of a medium-sized network (~100 nodes) with ~7 disconnected subcomponents, and have a standard
visNetwork()
with standardvisPhysics()
and standardvisLayout()
. 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 extendcentralGravity
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!
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 :(
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)
