Plot the large network in R language

Viewed 454

enter image description hereI have the graph data set named "WOS_graph", it is quite big data set with 5291 , I plotted the data , but in the plot it does not seems 5291 vertices, it shows less, can some one help me to plot correctly?

Also the data set can be found here: https://drive.google.com/file/d/1I96BAUo8TjJMWCWpn_SIhp54snfZ0Bd5/view?usp=sharing

library("igraphdata")
library("igraph")
library("network")
library("statnet")



nodeWOS <- data.frame(WOS)
#nodePRIN
relationsp <- as.matrix(WOSFull)

WOS_graph = graph_from_adjacency_matrix(relationsp, mode="undirected",weighted = TRUE)
WOS_graph



par(mar=c(0,0,2,0))
#deg <- degree(WOS_NET,rescale=TRUE)
#V(WOS_graph)$size <- deg*3000
#V(WOS_graph)$color <-#ifelse(V(WOS_graph)$Author.Type=="Italian_researchers","red", "blue")
l=layout.lgl(WOS_graph)
plot(WOS_graph,edge.color="gray60"
  ,pad=0.4,vertex.label=NA,layout=l,vertex.size=2)
  title(main="Large Graph Layout", cex.main=1)
1 Answers

Good observation! Nothing like 5291 vertices are visible, but with a little bit of work, you can track down what is going on.

First, I want to adjust your layout slightly. You created your layout with

l=layout.lgl(WOS_graph)

I did not want to wait as long as that took so I used

set.seed(1234)
l = layout_with_lgl(WOS_graph, maxiter=20)

But using this directly makes the plot difficult to analyze because plot rescales the data. Quoting the help page ?igraph.plotting

rescale
Logical constant, whether to rescale the coordinates to the [-1,1]x[-1,1] interval.
Defaults to TRUE, the layout will be rescaled.

I want the values in the layout to be exactly the locations plotted so I will rescale the layout to this range myself.

l[,1] = 2* (l[,1] - min(l[,1])) / (max(l[,1]) - min(l[,1])) - 1
l[,2] = 2* (l[,2] - min(l[,2])) / (max(l[,2]) - min(l[,2])) - 1

Now the values in the layout will match the plot locations on the graph. But what do those plot locations look like?

summary(l)
       V1                   V2            
 Min.   :-1.0000000   Min.   :-1.0000000  
 1st Qu.:-0.0006389   1st Qu.:-0.0009035  
 Median :-0.0000206   Median : 0.0000625  
 Mean   :-0.0066251   Mean   : 0.0028521  
 3rd Qu.: 0.0009063   3rd Qu.: 0.0002478  
 Max.   : 1.0000000   Max.   : 1.0000000 

Notice that while the full range [-1,1] is used, most of the values are very close to zero. I experimented around a little to find a good range for this discussion. You could try other ranges, but in a tiny box near the origin we get

length(which(abs(l[,1]) < 0.005 & abs(l[,2]) < 0.005))
[1] 4852

So 4852 vertices are in that box and the remaining 439 points are outside. What does that look like? Using (a slight modification of) your graph, I added a red box enclosing the dense are near the origin.

plot(WOS_graph, edge.color="gray60", pad=0.4,
    vertex.label=NA, layout=l, vertex.size=4)
title(main="Large Graph Layout", cex.main=1)
rect(-0.005, -0.005, 0.005, 0.005, border="red", col="red")

Full-scale plot with small red rectangle

If you look very closely, you can see a tiny red box in the center of the graph. That box contains 4852 vertices. Of course, when you graph them at full size like in this plot, they all look like they are in exactly the same pace, so it looks like one vertex.

To see this better, let's use the same layout but zoom in to the selected range [-0.005, 0.005], the tiny red box.

plot(WOS_graph, edge.color="gray60", pad=0.4,
    vertex.label=NA, layout=l, vertex.size=0.02,
    xlim=c(-0.005, 0.005), ylim=c(-0.005, 0.005))
title(main="Large Graph Layout - Zoomed", cex.main=1)
rect(-0.005, -0.005, 0.005, 0.005, border="red")

Zoomed graph

Now, the vertices that you were seeing before are mostly off-screen. You do see some edges crossing this region that connect the off-screen vertices. But mainly, now you can see that there were many vertices packed into this tiny region.

Related