2

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

SWR
  • 507
  • 1
  • 8
  • 17
  • Have you looked at `?igraph.plot`? Please try to do some research on your own and share what you've tried and how it didn't work before posting here. – Justin Jun 19 '13 at 20:13
  • @Justin: Well ?igraph.plot does not actually work with my version but I checked the plot commands of igraph anyway. Didn't find a command that creates the plot I need. What thought is that I first need a matrix of the corresponding source and target node's degrees. After that I can try to plot it with points (as shown above) or with some kind of correlation matrix plot. But I have difficulties to bring my thoughts into R code. – SWR Jun 19 '13 at 21:11

1 Answers1

3

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])
Vincent Zoonekynd
  • 31,893
  • 5
  • 69
  • 78
  • Thank you. I tried it with your code and it pretty much worked. However I think something with the rank process went wrong. I updated my initial post above. If you could take a look that would be perfect. Thx again. – SWR Jun 20 '13 at 09:21
  • Oh perfect thx. I also tried with `sort`but your are right, `order`is the correct way to go. – SWR Jun 20 '13 at 11:05
  • I cannot reproduce this.`image()` does not accept the adjacency matrix(?) – jO. Nov 21 '14 at 14:53
  • 1
    @jO.: get.adjacency now returns a sparse matrix: you need to explicitly load the Matrix package. – Vincent Zoonekynd Nov 22 '14 at 05:49