user3079834 user3079834 - 9 months ago 45
R Question

R plot random graph with same structure

I'm creating a random graph in

with the

g <-, 0.25)

This creates the following plot:

random graph

As you can see, it creates two different plots - even given the same nodes and edges. How can I make R plot the same plots, so I can highlight some edges/nodes while having the same order.

The goal is to create a random network with some degree of probability that two nodes are connected by an edge (above example is
nodes). Then this graph is plotted with the nodes on the same spot (even if the node size variies) everytime I plot it.

How do I do this? Note that I'm not limited to
g <-, 0.25)
- it just did the job with the random network quite well.

Answer Source

As default in igraph layout= layout_nicely which recalculated each plot

You can try to specify layout as matrix or as function to get coordinates


Either a function or a numeric matrix. It specifies how the vertices will be placed on the plot.

If it is a numeric matrix, then the matrix has to have one line for each vertex, specifying its coordinates. The matrix should have at least two columns, for the x and y coordinates, and it can also have third column, this will be the z coordinate for 3D plots and it is ignored for 2D plots.....

For example

g <-, 0.25)
g$layout <- layout_as_star

Give you enter image description here

or layout_componentsenter image description here

Full list you can find here