# Libraries --------------------------------------------------------------
library(visNetwork)
library(igraph)
## 
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
## 
##     decompose, spectrum
## The following object is masked from 'package:base':
## 
##     union
library(geomnet) #where dataset is pulled
## Loading required package: ggplot2
# Data Preparation -------------------------------------------------------
#Load dataset
data(lesmis)

#Nodes
nodes <- as.data.frame(lesmis[2])
colnames(nodes) <- c("id", "label")
nodes$id <- nodes$label

#Edges
edges <- as.data.frame(lesmis[1])
colnames(edges) <- c("from", "to", "weight")

#Create graph for the algorithms
g <- graph_from_data_frame(edges, directed = FALSE)
# Community Detection ----------------------------------------------------
#Create graph for Louvain
graph <- graph_from_data_frame(edges, directed = FALSE)

#Louvain Comunity Detection
cluster <- cluster_louvain(graph)

cluster_df <- data.frame(as.list(membership(cluster)))
cluster_df <- as.data.frame(t(cluster_df))
cluster_df$label <- rownames(cluster_df)

#Create group column
nodes <- merge(x = nodes, y = cluster_df, by = "label", all.x = TRUE)
colnames(nodes)[3] <- "group"

Zoom in - out & Click on single node

visNetwork(nodes, edges)