Since v3.0.0 you can color the nodes by cluster. Simply use sg_cluster with your igraph clustering algorithm of choice.

nodes <- sg_make_nodes() 
edges <- sg_make_edges(nodes, 17)

sigmajs() %>% 
  sg_nodes(nodes, id, size) %>% 
  sg_edges(edges, id, source, target) %>% 
  sg_layout() %>% 

Clustering is brilliant, in part, because (most) are bottom-up approaches; the number of cluster is not pre-defined. However, this might make the above approach somewhat awkward as the node colors should be discrete. In an interactive environment sg_cluster prints the number of clusters identified to the console, so you could then set the exact number of colors needed then re-run the graph.

Perhaps a better approach is to use the helper function sg_get_cluster to return nodes with an added column, the group they belong to. The helper also lets you set (or re-set) the node colors according to the group they belong to.

Let’s take a look at an example