R and iGraph: Coloring Community Nodes by attributes

When doing community detection on networks, sometimes we have more than connections between entities. These entities represent something in reality that we might want to represent also in the network visualisation. Consider the following example extracted from the Nexus repository

library(igraph)
gg <- nexus.get("Davis")
plot(gg)

plot of chunk loading

I'm using the Davis Dataset. This is the dataset collected by Davis et al[1] in the 1930s that represent observed attendance at 14 social events by 18 Southern women.

Not taking into account that this graph is a bipartite graph, let's just try to partition the graph into communities. Is there a natural divide? Let's color the nodes according to the community they belong:

gg.com <- fastgreedy.community(gg)
V(gg)$color <- gg.com$membership + 1
plot(gg)

plot of chunk communities

As we see the algorithm found 2 communities and at first inspection the division seams reasonable. In any case remember that there's another natural division that the algorithm couldn't find: the bipartite relation Event / Woman. Each node has this other property that says “Is Woman” or “Is Event”. Let's use that to characterise the graph in a different way. We have 14 Events. For these we'll change it's shape.

V(gg)[V(gg)$type == 1]$shape <- "square"
V(gg)[V(gg)$type == 0]$shape <- "circle"
plot(gg)

plot of chunk events

[1] “Allison Davis, Burleigh Bradford Gardner, Mary R. Gardner, Deep south: a social anthropological study of caste and class, University of Chicago Press (1941).”