Plotting the coreness of a network with R and igraph

Briefly, the k-core of a graph corresponds to the maximal connected subgraph whose vertices are at least of degree k within the subgraph. It is an interesting tool to analyze the connectivity of a network, and it is used in several domains, such as clustering, community discovery and anonymity.

However, it can be quite useful to visualize the coreness structure of small or medium networks in order to better understand the concept. To the best of our knowledge, there is no layout in igraph to properly visualize this concept. Although the code is very simple, we will show it here with a minimum example.

CorenessLayout <- function(g) {
coreness <- graph.coreness(g);
xy <- array(NA, dim=c(length(coreness), 2));

shells <- sort(unique(coreness));
for(shell in shells) {
v <- 1 - ((shell-1) / max(shells));
nodes_in_shell <- sum(coreness==shell);
angles <- seq(0,360,(360/nodes_in_shell));
angles <- angles[-length(angles)]; # remove last element
xy[coreness==shell, 1] <- sin(angles) * v;
xy[coreness==shell, 2] <- cos(angles) * v;
}
return(xy);
}

# g is the network
# compute coreness
coreness <- graph.coreness(g);
# assign colors
colbar <- rainbow(max(coreness));
# create layout
ll <- CorenessLayout(g);
# plot
plot(g, layout=ll, vertex.size=15, vertex.color=colbar[coreness], vertex.frame.color=colbar[coreness], main='Coreness');

Result looks like this one (Karate network):

karate

Advertisements
This entry was posted in Data Mining, Graph Mining and tagged , , . Bookmark the permalink.

One Response to Plotting the coreness of a network with R and igraph

  1. fjarroyave says:

    # Plotting the coreness of a network with R and igraph: transform angles as radians is needed.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s