Question

I found the figure below in literature about assortativity (for networks). I would like to plot my network in a similar way with R & igraph. Every point on the graph corresponds to a network edge. In my case x axis should represent the source node's degree, y axis the target node's degree. I am a beginner in R and therefore would very much appreciate if someone could help me to plot this. enter image description here

I now used the code from Vincent Zoonekynd and got the figure below. However I think that it still doesn't show exactly the right thing. The nodes on the axis should be ranked by their degree. When I look at the plot, I see some nodes with high degree which are plased around axis mark 42, 100 or 175. This makes not much sense. Is there something wrong with the rank process here?

A <- get.adjacency(USAN_g_num)            
image(A,  ylim=c(0,627))             
i <- rank( degree(USAN_g_num), na.last=NA, ties.method="first" )
image(A[i,i], ylim=c(0,627)) 

(I added an ylim to the code so that both, low-low degrees and high-high degrees are plottet in the same corner bottom-left and upper-right) But it is correct that my plot should look different from the one I showed above, since my data is disassortative. enter image description here

Was it helpful?

Solution

It looks like the adjacency matrix of a graph, with the nodes sorted by degree.

# Sample data
library(igraph)
library(Matrix)
g <- erdos.renyi.game(10, p=1/2) + erdos.renyi.game(10, p=1/2)

# Plot the adjacency matrix
A <- get.adjacency(g)
image(A)

# In this example, sorting the nodes by degree is not a good idea
i <- order( degree(g) )
image(A[i,i])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top