#Please run LoadingFiles.R before running this


#How one runs the community detection algorithms on the graph
greedyPartition<- cluster_fast_greedy(collabGraphLCC,weights=E(collabGraphBig)$weight)
infoMapPartition<- cluster_infomap(collabGraphLCC,e.weights=E(collabGraphBig)$weight)
propLabelsPartition<- cluster_label_prop(collabGraphLCC,weights=E(collabGraphBig)$weight)
louvainPartition<- cluster_louvain(collabGraphLCC,weights=E(collabGraphBig)$weight)
randWalksPartition<- cluster_walktrap(collabGraphLCC,weights=E(collabGraphBig)$weight)


#To compare partitions using the adjusted rand index, use 'compare(...)'. 
#An example is below, change partition1 and partition2 to compare different ones

partition1<- greedyPartition
partition2<- louvainPartition
compare(partition1,partition2,method="adjusted.rand")

#To find the largest size and number of communities in the partition one can run the below commands
length(sizes(partition1))  #number of communities
max(sizes(partition1))     #largest community size


#Plotting the size distribution of 'partition1'
#to change the x axis change 'xlimit' below
xlimit<- 1150

Data<- data.frame(x=c(1:length(partition1)),size=sizes(partition1))
aaa<- ggplot(DD,aes(x=size.Freq))
aaa+geom_histogram(binwidth=50,closed='left',boundary=50,aes(y=..count../sum(..count..)),fill="slateblue4",col=I("black"))+
ylab("Probability")+
xlab("Community Size (no. of nodes)")+
ggtitle("")+
theme(plot.title = element_text(hjust = 0.5,size=45),text=element_text(size=35),plot.margin=margin(3,30,10,3))+
coord_cartesian(xlim = c(0, xlimit),ylim = c(0,0.37))

