Ggraph: Fix position

Created on 13 Jan 2016  路  3Comments  路  Source: thomasp85/ggraph

Looking forward to the development of this package!. This is more of a feature request than an issue. I was just wondering if it is or will be possible to fix the position of a network layout. i.e. if you were to re-execute this code:

ggraph(graph = gr, layout = 'fr') + geom_edge_link(aes(size = weight), color = 'grey', alpha = 0.5) + geom_node_point(aes(color = class), size = 10) + coord_fixed() + ggforce::theme_no_axes()

that the layout would always be the same? I don't think this is doable through igraph and perhaps that means also not possible here? My rationale is because it would be great to be able to update the same network temporally showing how edges change - this would only make sense visually if the nodes remain in the same place.

Most helpful comment

Just as a bonus for filing the first issue I implemented it for you right away in 1a6447668dbe5723e08e41d70767073fdb8fea9a

Now do:

# do something to create a data.frame with x and y positions for your nodes (e.g. using createLayout)
ggraph(graph = gr, layout = 'manual', node.positions = nodes) + geom_edge_link()
# Where 'nodes' are the data.frame with the node position

All 3 comments

This is already possible if you create the layout up-front:

layout <- createLayout(graph = gr, layout = 'fr')
ggraph(data=layout) + geom_edge_link() # etc...

Ah... I just reread your post. You want to plot - change the graph and then plot again..? That is not fully as straightforward yet, but I'll most certainly add a layout = 'manual' in the near future. You can achieve it in igraph by supplying a two-column matrix as the layout in the plot function instead of the name of a layout function...

Currently with ggraph the workaround would be:

layout <- createLayout(graph = gr, layout = 'fr')
ggraph(data=layout) + geom_edge_link() # etc...

# do something to graph edges

attr(layout, 'graph') <- gr
ggraph(data=layout) + geom_edge_link() # etc...

Just as a bonus for filing the first issue I implemented it for you right away in 1a6447668dbe5723e08e41d70767073fdb8fea9a

Now do:

# do something to create a data.frame with x and y positions for your nodes (e.g. using createLayout)
ggraph(graph = gr, layout = 'manual', node.positions = nodes) + geom_edge_link()
# Where 'nodes' are the data.frame with the node position
Was this page helpful?
0 / 5 - 0 ratings