[BioC] Rgraphviz - how to use node positions from one graph as node positions in another?
Kasper Daniel Hansen
khansen at stat.Berkeley.EDU
Wed Jul 25 05:37:17 CEST 2007
On Jul 24, 2007, at 3:47 PM, Søren Højsgaard wrote:
> I create a "graphNEL" graph with a neato layout. I would like to
> get the locations of nodes in that graph and use these locations
> when creating subsequent graphs (such that all the graphs have the
> nodes in the same locations). How can this be achieved?? Apologies
> if this issue has come op on the list, but I haven't found it...
Hi Soeren
This is most likely going to be non-trivial. The idea of Graphviz is
that it does the layout for you - ie. it assigns (x,y) positions to
the nodes and a spline to the edges. What you are suggesting would
require the capability of Graphviz to accept certain nodes as being
fixed in the layout universe, and I don't think that is possible (I
may be wrong though). You can give Graphviz a hint that certain
things should be close together etc, but you are not guaranteed that
the (x,y) placement will be the same once you start deleting edges.
You might want to have a look at graphviz.org where they have some
reasonable user guides.
What you can do (and what would probably make sense if you are trying
to show a graphical model, as I guess you are), is to run RGraphviz
with the most complicated graph you have and then use this layout as
reference. When you then delete edges/nodes you just don't draw them.
This is quite easy because we render the graph in R.
The code behind
plot(SomeGraph.graphNEL)
is essentially
SomeGraph.Ragraph = layoutGraph(SomeGraph.graphNEL)
The Ragraph object is now a fairly complicated object, but
essentially it contains (x,y) positions etc. This object is then
plotted using standard R routines in the
getMethod("plot", "Ragraph")
You will see the code is very straightforward, using functions such
as AgNode and drawNode. With your experience it should be easy to
play around with this.
In case you are wondering about the abysmal naming scheme it comes
from the underlying C code of Graphviz where the basic object is
Agraph ("a graph" I think) with Agnode ("A graph node"), the R
versions of the C objects are named accordingly.
There may be an easier way I don't know about. Sometimes people can
do magic with the right Graphviz settings. If you encounter some
capabilities not in Rgraphvis, tell us.
What you want to do makes a lot of sense from a certain perspective,
so if you get some nice code working am sure we can add it in.
Kasper
More information about the Bioconductor
mailing list