[R] igraph and plotting connected components

Gabor Csardi csardi at rmki.kfki.hu
Tue Oct 9 11:26:06 CEST 2007


Dieter,

there are a couple of ways to do this in igraph, eg.
you can decompose the graph into separate components with

g <- erdos.renyi.game(100, 1/100)
graphs <- decompose.graph(g)

and then you will have a list of graphs. If you assign some vertex 
ids as vertex attributes then you can keep track of which vertex is 
in which component:

V(g)$label <- seq(vcount(g))
graphs <- decompose.graph(g)

and eg. to plot the largest component:

largest <- which.max(sapply(graphs, vcount))
plot(graphs[[largest]], layout=layout.fruchterman.reingold)

Or you can use a layout algorithm which is not troubled by the
unconnected graph, like Fruchterman-Reingold:

plot(g, layout=layout.fruchterman.reingold)

Gabor

On Mon, Oct 08, 2007 at 05:27:52PM -0700, Dieter Best wrote:
> Hello there,
>    
>   I am using the igraph package to build graphs from my data. If I plot a graph though, it's not easy for me to see what's going on. Does anybody know how to rearrange a graph to get a plot without too many crossing lines? Maybe other packages?
>    
>   Thanks a lot in advance for any pointers,
>    
>   -- D
>    
>    
>     
> 
>        
> ---------------------------------
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Csardi Gabor <csardi at rmki.kfki.hu>    MTA RMKI, ELTE TTK



More information about the R-help mailing list