# NOT RUN {
# 1) generate a random bipartite graph
set.seed(123)
g <- sample_bipartite(100, 50, p=0.1)
V(g)$name <- V(g)
# }
# NOT RUN {
# 2) obtain and append the community
cs <- igraph::cluster_louvain(g)
V(g)$community <- cs$membership
ig <- xAddCoords(g, node.attr="community",
edge.color.alternative=c("grey50","grey95"))
gp <- xGGnetwork(ig, node.label='name', node.label.size=2,
node.label.color='black', node.label.alpha=0.8, node.label.padding=0,
node.label.arrow=0, node.label.force=0.002, node.xcoord='xcoord',
node.ycoord='ycoord', node.color='community',
node.color.title='Community', colormap='jet.both', ncolors=64,
zlim=NULL,
edge.color="color",edge.color.alpha=0.5,edge.curve=0,edge.arrow.gap=0)
## make it discrete for the colorbar
gp +
scale_colour_gradientn(colors=xColormap('jet')(64),breaks=seq(1,8)) +
guides(color=guide_legend(title="Community"))
# }
Run the code above in your browser using DataLab