Skip to content

Instantly share code, notes, and snippets.

@beemyfriend
Last active September 6, 2018 00:48
Show Gist options
  • Save beemyfriend/0acdfcc92786495f1dde121d119939cc to your computer and use it in GitHub Desktop.
Save beemyfriend/0acdfcc92786495f1dde121d119939cc to your computer and use it in GitHub Desktop.
Using walk trap for DAG community detection
library(igraph)
g <- make_tree(10) +
edge(6, 9,
7, 10,
8, 9)
is_dag(g)
wc <- cluster_walktrap(g)
l <- matrix(
c(1, 5,
2, 1,
2, 10,
4, 1,
4, 4,
3, 7,
4, 10,
5, 3,
5, 6,
5, 9),
ncol = 2,
byrow =T
)
png('maybe_dag_community.png')
plot(wc, g, layout= l)
dev.off()
g2 <- make_tree(15) +
edges(4, 7,
8, 14,
9, 10,
15, 13)
is_dag(g2)
wc2 <- cluster_walktrap(g2)
l2 <- matrix(
c(1, 5,
2, 3,
2, 7,
3, 4.5,
4, 1,
4, 10,
3, 6.5,
5, 4.5,
4, 3,
5, 3,
5, 1,
5, 10,
5, 8,
5, 6.5,
4, 8),
ncol = 2,
byrow = T
)
png('maybe_dag_community2.png')
plot(wc2, g2, layout = l2)
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment