data("table5.2")
if(requireNamespace("igraph")) {
# note special incantation to get the "correct" graph structure
g <- igraph::graph_from_adjacency_matrix(table5.2, mode = 'upper', diag = FALSE, weighted = TRUE)
# visualize
op <- par(no.readonly = TRUE)
par(mar = c(0,0,0,0))
plot(g)
plot(g, vertex.size = sqrt(igraph::degree(g) * 25), vertex.label.family = 'sans')
# find communities
cm <- igraph::cluster_walktrap(g)
plot(cm, g, vertex.label.family = 'sans')
par(op)
}
Run the code above in your browser using DataLab