When you use the contract()
function in R/igraph are the communities supposed to be linked to one another? Or are they supposed to appear as isolated? Some of the communities in my example are linked, some of them are isolated. Does anyone know why this is?
library(igraph)
library(dplyr)
library(visNetwork)
set.seed(1234)
#create file from which to sample from
x5 <- sample(1:10000, 10000, replace=T)
#convert to data frame
x5 = as.data.frame(x5)
#create first file (take a random sample from the created file)
a = sample_n(x5, 9000)
#create second file (take a random sample from the created file)
b = sample_n(x5, 9000)
#combine
c = cbind(a,b)
#create dataframe
c = data.frame(c)
#rename column names
colnames(c) <- c("a","b")
#create graph
graph <- graph.data.frame(c, directed=F)
graph <- simplify(graph)
cfg <- cluster_fast_greedy(graph)
#contract clusters
contracted <- simplify(contract(graph, membership(cfg), vertex.attr.comb=toString))
#visnetwork plot
visIgraph(contracted) %>% visOptions (highlightNearest = TRUE) %>% visIgraphLayout(layout = "layout_with_fr") %>%
visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE) %>%
visInteraction(navigationButtons = TRUE)
#without visnetwork
plot(contracted)
Some clusters are still connected to each other, some are isolated. Does anyone know why this is?
Thanks
Stack Link: https://stackoverflow.com/questions/64960236/formatting-graphs-in-r