[BioC] fontsize in Rgraphviz
Mark W Kimpel
mwkimpel at gmail.com
Wed Jan 30 17:34:06 CET 2008
Sorry for the complex prior example, I shouldn't write emails late at
night. Below is a self-contained, reproducible example.
I've made some progress and can get the following script to flow without
error messages. The fontsize, however, is not varying as I believe it
should and when I substitute "ellipse" for circle the width and height
parameters do not appropriately effect the shape.
I also do not understand where I can specify "neato" vs. "dot" for the
rendering layout. Also, where to specify a title.
Thanks, mark
####################
require(Rgraphviz)
# Generate random graph
set.seed(123)
nodeNames <- letters[1:10]
M <- 1:4
g1 <- randomGraph(nodeNames, M, .2)
nAttrs <- list()
#node shapes
nAttrs$shape <- rep("circle", length(nodeNames))
names(nAttrs$shape )<- nodeNames
#node width
nAttrs$width <- rep(3, length(nodeNames))
names(nAttrs$width)<-nodeNames
#node height
nAttrs$height <- rep(3, length(nodeNames))
names(nAttrs$height)<-nodeNames
#node colors
nAttrs$fillcolor <-rep("black", length(nodeNames))
names(nAttrs$fillcolor) <- nodeNames
#font color
nAttrs$fontcolor <- rep("white", length(nodeNames))
names(nAttrs$fontcolor)<-nodeNames
#font size
nAttrs$fontsize <- rep(c(1, 2), (length(nodeNames)/2))
names(nAttrs$fontsize)<-nodeNames
postscript(file="my.test.graph.ps", paper="special",width=4, height=5)
#set up graphics device
x <- layoutGraph(g1)
nodeRenderInfo(x) = nAttrs
renderGraph(x)
dev.off()## close the graphics device
Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry
Indiana University School of Medicine
15032 Hunter Court, Westfield, IN 46074
(317) 490-5129 Work, & Mobile & VoiceMail
(317) 204-4202 Home (no voice mail please)
mwkimpel<at>gmail<dot>com
******************************************************************
Deepayan Sarkar wrote:
> On 1/29/08, Mark W Kimpel <mwkimpel at gmail.com> wrote:
>> Deepayan,
>>
>> Thanks for your efforts, it looks like you are working on major changes
>> to Rgraphviz for BioC 2.2.
>>
>> Your example worked for me (with R-devel), but I can't get my own
>> function to work. Below is my code, or what I hope is the relevant part,
>> with the error output. It looks to me like layoutGraph is looking for a
>> way to render a "neato" graph and can't find it, but I'm probably wrong.
>> It also looks to me like you are making some major changes to the way
>> node and edge attributes are passed to the rendering engine, so maybe
>> the parameters I used to pass to plot(my.graphNEL) are not working.
>>
>> Let me know what you think I am doing wrong. Mark
>
> The error messages are not telling me much. Can you provide a
> reproducible example (preferably something simple)?
>
> -Deepayan
>
>> [1] "created graphAM"
>> [1] "created graphNEL"
>> Error in layoutGraph(result.gN, layout.param, layoutfun = "dot",
>> nodeAttrs = nAttrs, :
>> could not find function "layoutFun"
>>
>> Enter a frame number, or 0 to exit
>>
>> 1: result.matrix.graph.func(result.matrix = cocite.mat.sig, no.edges =
>> TRUE, m
>> 2: switch(file.output, ps = {
>> 3: layoutGraph(result.gN, layout.param, layoutfun = "dot", nodeAttrs =
>> nAttrs,
>>
>> Selection:
>>
>> #font size
>> if(file.output != "screen"){
>> #cex.vec <-floor(22 * nodeAttrs(result.gN)$nodeWidth)
>> cex.vec <- rep(48, length(nodes(result.gN)))
>> } else {cex.vec <-rep(18, length(nodeAttrs(result.gN)$nodeWidth))}
>> names(cex.vec) <- nodes(result.gN)
>>
>> fileName<-paste(experiment, contrast, "FDR", FDR, "Graph",
>> "ps", sep=".")
>> postscript(file=fileName, paper="special",width=width,
>> height=height) #set up graphics device
>> x <- layoutGraph(result.gN, layout.param, layoutfun = "dot",
>> nodeAttrs = nAttrs, edgeAttrs = eAttrs,
>> main=paste("Experiment:", experiment, "; Contrast:",
>> contrast,"; FDR:", FDR,
>> ";Total Genes:", length(nodes(result.gN)), "; Total
>> Connections:",
>> round(aveNumEdges(result.gN)*length(nodes(result.gN)),
>> digits=0),"; Min. connections ==",
>> min.edges, "; Min. citations per connection ==",
>> min.cites, "; Additional search criteria:",
>> termAdditional, sep=" "))
>> nodeRenderInfo(x) = list(fontsize = cex.vec)
>> renderGraph(x)
>> dev.off()## close the graphics device
>>
>> Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry
>> Indiana University School of Medicine
>>
>> 15032 Hunter Court, Westfield, IN 46074
>>
>> (317) 490-5129 Work, & Mobile & VoiceMail
>> (317) 204-4202 Home (no voice mail please)
>>
>> mwkimpel<at>gmail<dot>com
>>
>> ******************************************************************
>>
>>
>> Deepayan Sarkar wrote:
>>> On 1/25/08, Mark W Kimpel <mwkimpel at gmail.com> wrote:
>>>> I would like to vary the font size of node labels in Rgraphviz as I have
>>>> been varying node size by fold change magnitude. Unfortunately, many
>>>> attempts have failed and I continue to get the same font size. Here is
>>>> my code followed by sessionInfo()
>>>>
>>>> nAttrs$fontsize<-floor(22 * nodeWidth)
>>>>
>>>> nodeWidth is a vector of widths which vary by node according to fold
>>>> change. This works nicely, but font size does not.
>>> We have been playing an alternative rendering interface. With
>>> bioc-devel, I get varying node sizes and label size using
>>>
>>>
>>> set.seed(123)
>>> V <- letters[1:10]
>>> M <- 1:4
>>> g1 <- randomGraph(V, M, .2)
>>>
>>> cex.list <- runif(length(nodes(g1)))
>>> names(cex.list) <- nodes(g1)
>>>
>>> width.list <- seq(0.2, 2, length = length(nodes(g1)))
>>> names(width.list) <- nodes(g1)
>>>
>>> x <- layoutGraph(g1, nodeAttrs = list(width = width.list))
>>> nodeRenderInfo(x) = list(fontsize = 50 * cex.list)
>>> renderGraph(x)
>>>
>>>
>>>
>>> I'm not sure if this will work with Bioc 2.1.
>>>
>>> -Deepayan
>>>
>
More information about the Bioconductor
mailing list