## Create a graph with an interesting structure:
g <- graph.disjoint.union(graph.full(4), graph.empty(2,directed=FALSE))
g <- add.edges(g,c(3,4,4,5,4,2))
g <- graph.disjoint.union(g,g,g)
g <- add.edges(g,c(0,6,1,7,0,12,4,0,4,1))
## Find cohesive blocks:
gBlocks <- cohesive.blocks(g)
## Examine block membership and cohesion:
gBlocks$blocks
gBlocks$block.cohesion
## Plot the resulting graph with its block hierarchy:
plot(gBlocks, vertex.size=7, layout=layout.kamada.kawai)
## Save the results as Pajek ".net" and ".clu" files:
write.pajek.bgraph(gBlocks,file="gBlocks")
## An example that works better with the "kanevsky" cutset algorithm
g <- read.graph(file="http://intersci.ss.uci.edu/wiki/Vlado/SanJuanSur.net", format="pajek")
gBlocks <- cohesive.blocks(g, cutsetAlgorithm="kanevsky")
Run the code above in your browser using DataLab