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]]
graph, RBGL and Rgraphviz, all available at www.bioconductor.org 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. >-- Robert Gentleman, PhD Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N, M2-B876 PO Box 19024 Seattle, Washington 98109-1024 206-667-7700 rgentlem at fhcrc.org
On 08/10/2007 8:27 PM, 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?Rgraphviz in Bioconductor does a great job of this. It's a wrapper for the Graphviz library, so the R docs are a little sparse, but there's a tremendous amount of flexibility there. For example, library(Rgraphviz) nodes <- c("R", "Scheme", "S", "APL", "Lisp", "Fortran", "Ratfor", "CLOS", "C", "Haskell") edges <- list(R=character(0), Scheme=c("R","Haskell"), S="R", APL=c("S", "Haskell"), Lisp=c("Scheme", "S", "CLOS","Haskell"), Fortran="Ratfor", Ratfor="S", CLOS="S", C=c("S","R","Ratfor"), Haskell="R") g <- new("graphNEL", nodes=nodes, edgeL=edges, edgemode="directed") plot(g) Duncan Murdoch
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