user3079834 - 1 year ago 64

R Question

I'm creating a random graph in

`R`

`igraph`

`library(igraph)`

g <- erdos.renyi.game(12, 0.25)

par(mfrow=c(1,2))

plot(g)

plot(g)

This creates the following plot:

As you can see, it creates

The goal is to create a random network with some degree of probability that two nodes are connected by an edge (above example is

`p=0.25`

`n=12`

How do I do this? Note that I'm not limited to

`g <- erdos.renyi.game(12, 0.25)`

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

layout

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 <- erdos.renyi.game(12, 0.25)
g$layout <- layout_as_star
par(mfrow=c(1,2))
plot(g)
plot(g)
```

Full list you can find here