[BioC] Graph Layout

Vincent Carey 525-2265 stvjc at channing.harvard.edu
Mon Jan 30 20:36:07 CET 2006


> Hi,
>
>  I want to draw graph using a spring-embedding.
>
>  Regards,
>  Kaustubh

This takes a little bit of programming.  The following
is far from an ideal design, but gives some of the flavor
of how you can use the RBGL layout functions.  As far
as I can tell there are three: circle.layout,
kamada.kawai.spring.layout, and fruchtermanReingoldForceDirectedLayout.
I am not sure the latter is behaving correctly, but the first
two are.

Now source the following function into your R session

crudeGraphPlot <- function(g, alg=circle.layout, ...) {
#
# the alg parameter is a function that computes the
# layout of g, returning it as a list of length 1
# with two rows: top row is x coordinates, bottom is
# y coordinates, and node names are used as colnames
# the ... are passed to segments()
#
  layout <- alg(g)[[1]]
  plot( layout[1,], layout[2,], pch=nodes(g), axes=FALSE,
    xlab="", ylab="", main=substitute(g), cex=1.4 )
  ee <- edges(g)
  src <- names(ee)
  ds <- function(nn1, nn2, lob) segments(lob[1,nn1], lob[2,nn1],
        lob[1,nn2], lob[2,nn2], ...)
  for (s in src) sapply(ee[[s]], function(x) ds(s, x, layout))
  invisible(NULL)
}

load RBGL and do example(kamada.kawai.spring.layout).  This
will create a graph called coex in your workspace.

Now crudeGraphPlot(coex) will give the default
circular layout on your graphics device

crudeGraphPlot(coex, alg=kamada.kawai.spring.layout, col="green")

will show you the spring layout with green edges.

You will see that the layout of the spring layout is provided
by the "neato" option of Rgraphviz --
library(Rgraphviz)
plot(coex, "neato")

so you can use either the layouts computed by RBGL with programming
like that given above, or use graphviz.  There is much more configurability
in the Rgraphviz package, but there may be some algorithms in RBGL
not available in graphviz.


>
> Li Long <lilong at isb-sib.ch> wrote:
> If what you want is just to draw the graph, you really should consider
> using Rgraphviz package, where "neato"/"fdp" do the layout using these
> algorithms.
>
> Li
>
> > Dear All,
> >
> >  How can I use the numbers returned by the layout functions (like,
> > kamada.kawai spring layout) for actually drawing a graph?
> >
> >  I could not find it in the RBGL vignettes.
> >
> >  Thank you and regards,
> >  Kaustubh
>
>
>
>
>
> ---------------------------------
>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
>



More information about the Bioconductor mailing list