Skip to content

Instantly share code, notes, and snippets.

@gweissman
Last active May 24, 2018 15:11
Show Gist options
  • Save gweissman/9b25f79fabac7803462138b7dd533ca8 to your computer and use it in GitHub Desktop.
Save gweissman/9b25f79fabac7803462138b7dd533ca8 to your computer and use it in GitHub Desktop.
How to highlight the giant component of a graph using igraph
# highlight communities and clusters in an igraph plot
library(igraph)
g <- erdos.renyi.game(50, .02)
# plot regular
plot(g)
# get the components of the graph
comps <- components(g)
# which is biggest?
giant_id <- which.max(comps$csize)
# now plot again marking the largest component
plot(g, mark.groups = list(comps$membership == giant_id), mark.col = 'green')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment