ggraph icon indicating copy to clipboard operation
ggraph copied to clipboard

Allowing half manual layouts?

Open llrs opened this issue 6 years ago • 2 comments

Many thanks for such wonderful packages I been using them more and more!

However, I can't find a functionality I think could be useful.I would like to be able to select some nodes and distribute at certain positions and let other nodes using the automagically positions. I'm not sure how to do that using the manual layout. Could that be done?

Something on these lines:

# To allow the nodes of to be in a square
# in node data  (following tidygraph) there would be a column describing the type of the node
ggraph(graph, layout = 'kk') + 
    geom_edge_fan(aes(alpha = ..index..), show.legend = FALSE) + 
    geom_node_point(select = type == "A" , position = "square") # Or circle 

# To allow the nodes of some genes to be as it would be on a map or from cmdscale
df <- cmdscale(matrix_distances_between_genes)
ggraph(graph, layout = 'kk') + 
    geom_edge_fan(aes(alpha = ..index..), show.legend = FALSE) + 
    geom_node_point(select = type == "A" , position = df) 

Of course, this could be changed and a better function names could be selected. Perhaps it is already doable with some combination of plottings and I might have missed. I hope you can give me directions. Thanks

llrs avatar May 28 '18 13:05 llrs

This is something that needs to be implemented as a new layout. You could probably cook a force-directed one up pretty quickly using the particles package

thomasp85 avatar Aug 12 '19 20:08 thomasp85

Many thanks for the suggestion

llrs avatar Aug 13 '19 10:08 llrs

@schochastics is this something that could be added as (yet another) constrained stress layout?

thomasp85 avatar Jan 14 '24 23:01 thomasp85

I think so. I will put it on the graphlayouts todo list

schochastics avatar Jan 15 '24 06:01 schochastics

This is now implemented in graphlayouts

schochastics avatar Jan 17 '24 19:01 schochastics

@schochastics does the implementation support partial fixes, e.g. that one node has a fixed x coord but no fix on the y coordinate and so on. Or does the fixtures need to be complete?

thomasp85 avatar Jan 18 '24 07:01 thomasp85

Yes. The fixed coordinates can be arbitrary and dont need to include both x and y values

schochastics avatar Jan 18 '24 07:01 schochastics

great, so if all x coordinates are provided and no y-coordinates are provided it behaves exactly as layout_with_constrained_stress()?

thomasp85 avatar Jan 18 '24 07:01 thomasp85

Yes, I verfied that :-)

schochastics avatar Jan 18 '24 08:01 schochastics