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):

### Like this:

Like Loading...

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