g<-rgraph(20,tprob=0.075) #Generate a sparse random graph
#Find weak components
cd<-component.dist(g,connected="weak")
cd$membership #Who's in what component?
cd$csize #What are the component sizes?
#Plot the size distribution
plot(1:length(cd$cdist),cd$cdist/sum(cd$cdist),ylim=c(0,1),type="h")
#Find strong components
cd<-component.dist(g,connected="strong")
cd$membership #Who's in what component?
cd$csize #What are the component sizes?
#Plot the size distribution
plot(1:length(cd$cdist),cd$cdist/sum(cd$cdist),ylim=c(0,1),type="h")
Run the code above in your browser using DataLab