Ray92
Ray92

Reputation: 451

Random Network Graphs in R

I am implementing the code below to make an ER random network in R (6301 nodes,20777 edges) to compare it with a given directed network, but when i plot it, it looks nothing like a random network (no arrows/lines whatsoever)!

library(igraph)


rayyan <- erdos.renyi.game(6301,20777, type="gnm",directed = TRUE)

#plot graph
plot(rayyan)

# print degree
degree(rayyan)

# normalised degree distribution
plot(degree.distribution(rayyan), xlab="node degree")

transitivity(rayyan)

Thanks for your help

Upvotes: 1

Views: 1449

Answers (1)

G5W
G5W

Reputation: 37641

There are two main problems here.

  1. You graph is poorly laid out for display and
  2. Your graph is so busy that you are not going to see much.

Since you did not set the seed, we cannot reproduce exactly the graph that you got. I will recreate the graph with a particular random seed to make a reproducible example.

set.seed(1234)
rayyan <- erdos.renyi.game(6301,20777, type="gnm",directed = TRUE)
plot(rayyan)

Initial graph

I can't see anything. Partly, a disproportionate amount of the graph area is used to keep the nine single nodes separated from the rest. We can do better by leaving out these nodes. We can reduce the margins, leave off the node labels and make the arrow heads smaller to squeeze more into the small space available.

Single = c(354,437,593,1585,1635,2405,4705,5341, 5818)
rayyan2 = induced_subgraph(rayyan, V(rayyan)[-Single])
plot(rayyan2,vertex.size=3, vertex.label=NA,
     edge.arrow.size = 0.3, margin=-0.25)

Improved graph

At least, you can see that it is a graph now, but with 6292 nodes and 20777 edges, it is very crowded and hard to see. There is just too much to fit into that space.

Upvotes: 2

Related Questions