[BioC] Rgraphviz edge attributes can't be changed on Mac
Florian Hahne
fhahne at fhcrc.org
Fri Nov 2 00:23:12 CET 2007
Hi Weijun,
we are currently working on a more generalized API for rendering of
graphs. The idea here is to have all necesary rendering information as
part of the graph object, and also not to be so tightly linked to the
graphviz library, there are other layout engines around. In the latest
devel version of Rgraphviz there is a function layoutGraph which will
create the necessary layout information for a graph and the function
renderGraph which will plot a laid out graph. So the workflow is somehow
similar to what we have at the moment with agopen/plot. The rendering
parameters (color, line width, etc.) are separated from the layout
parameters and can be changed on a graph without the need for redoing
the layout. You can set and retrieve these parameters on the graph
object using the nodeRenderInfo, edgeRenderInfo and graphRenderInfo
functions. Also, you can set defaults using the graph.par function.
Layout parameters (node shapes, layout type, etc.) can still be passed
to the layout algorithm in the ususal fassion (edgeAttr, nodeAttr, ...).
Here's a little example:
library(graph)
library(Rgraphviz)
set.seed(123)
V <- letters[1:10]
M <- 1:4
g1 <- randomGraph(V, M, 0.8)
edgemode(g1) <- "directed"
x <- layoutGraph(g1)
x <- renderGraph(x)
## change some of the node rendering parameters
nodeRenderInfo(x) <- list(fill=c(a="red", b="blue"), textCol=c(e="orange"))
x <- renderGraph(x)
## and some of the edge rendering parameters
edgeRenderInfo(x) <- list(lwd=c("g~i"=3, "d~j"=5), lty=c("d~j"="dotted"))
x <- renderGraph(x)
## add some edge labels
labs <- edgeNames(x)
names(labs) <- labs
edgeRenderInfo(x) <- list(label=labs, fontsize=c("g~i"=20),
textCol=c("g~i"="green"))
x <- layoutGraph(x)
x <- renderGraph(x)
## title and subtitle
graphRenderInfo(x) <- list(main="An example graph", sub="showing the new
rendering capabilities")
x <- renderGraph(x)
## now set some defaults
graph.par(list(edges=list(fontsize=16, textCol="gray"),
graph=list("cex.main"=4)))
x <- renderGraph(x)
Note that this is all under heavy development and you need both the
latest Rgraphviz (1.17.11) and graph (1.17.10 ) versions from the devel
branch (best is to compile directly form the svn repository). Also the
documentation is still lacking behind a bit, but among too many other
things I am working on that. It would be really helpful if you could try
this out and tell me which of the things you want to do are not working
yet.
You can still get to the node locations if you want to add your own stuff by
nodeRenderInfo(x, c("nodeX", "nodeY"))
but these coordinates might not be too helpful as they are because they
are only valid within renderGraph's environment. You can emulate that
doing something like this:
par(mai=graphRenderInfo(x, "mai"), usr=graphRenderInfo(x, "usr"))
Cheers,
Florian
More information about the Bioconductor
mailing list