Anton
Anton

Reputation: 591

cluster walktrap returns three communities, but when plotting they are all on top of each other, with no visible clustering

I've been following documentation tutorials and even lecture tutorials step by step. But for some reason the output of my plot is like this: enter image description here

The output doesn't make any sense to me. There clearly is no structure, or communities in this current plot, as you can see that the bigger circles are all overlapping. Shouldn't this, in this case, return only a single community? Additionally the modularity of my network is ~0.02 which would again, suggest there is no community structure. But why does it return 3 communities?

this is my code: (exactly same as in documentation, with different dataset)

m <- data.matrix(df)
g <- graph_from_adjacency_matrix(m, mode = "undirected")
#el <- get.edgelist(g)

wc <- cluster_walktrap(g)
modularity(wc)
membership(wc)
plot(wc,g)

my data set looks is a 500x500 adjacency matrix in the form of a csv, with a 1-500 column and index names corresponding to a person.

I tried understanding the community class and using different types of variables for the plot, e.g. membership(wc)[2] etc. My thought is that the coloring is simply wrong, but nothing Ive tried so far seems to fix the issue.

Upvotes: 1

Views: 1484

Answers (1)

struggles
struggles

Reputation: 865

You can have inter-community connections. You're working with a graph of 500 nodes and they can have multiple connections. There will be a large number of connections between nodes of different communities, but if you conduct a random walk you're most likely to traverse connections between nodes of the same community.

If you separate the communities in the plot (using @G5W's code (igraph) Grouped layout based on attribute) you can see the different groups.

set.seed(4321)
g <- sample_gnp(500, .25)

plot(g, vertex.label = '', vertex.size = 5)
wc <- cluster_walktrap(g)
V(g)$community <-  membership(wc)
E(g)$weight = 1

g_grouped = g

for(i in unique(V(g)$community)){
  groupV = which(V(g)$community == i)
  g_grouped = add_edges(g_grouped, combn(groupV, 2), attr=list(weight = 2))
}

l <- layout_nicely(g_grouped)

plot( wc,g, layout = l, vertex.label = '', vertex.size = 5, edge.width = .1)

Red edges are intercommunity connections and black edges are intracommunity edges

enter image description here

Upvotes: 4

Related Questions