[BioC] Rgraphviz and node label placement

Paul Murrell p.murrell at auckland.ac.nz
Thu Apr 5 01:34:18 CEST 2012


Hi

There is a still-early-days package called 'gridGraphviz' (version 0.1) 
which you can use to draw the graph using the 'grid' package.  This 
makes it possible to modify the drawn graph after-the-fact.  For 
example, after running your code, you can do ...


library(gridGraphviz)
nodeShape <- rep("box", length(nodes(testG)))
names(nodeShape) <- nodes(testG)
rag <- agopen(testG, "",
               nodeAttrs=list(shape=nodeShape))
grid.newpage()
grid.graph(rag)
# Get label names
grobs <- grid.ls()
labelIndex <- grep("label", grobs$name)
labelPaths <- grobs$gPath[labelIndex]
for (i in 1:length(labelIndex)) {
     labelPath <- gPath(labelPaths[i], "label")
     oldY <- grid.get(labelPath)$y
     grid.edit(labelPath,
               label=theTerms[i],
               y=oldY - unit(5, "mm"), redraw=FALSE)
}
grid.refresh()


The important bit being the adjustment of the original 'y' value for 
node labels to be 5mm lower.

This is not EXACTLY like your original, but maybe it is close enough to 
do what you need (?)

Paul

On 31/03/12 01:08, Iain Gallagher wrote:
> Hello List
>
> Is is possible to place node labels below nodes rather than within them in Rgraphiviz? In the graph below I would like to plot labels below the nodes because many labels are too long to fit within the nodes.
>
>
> library(GO.db)
> library(GOstats)
> library(Rgraphviz)
>
> GOlist<- c('GO:0031994', 'GO:0043559', 'GO:0048186', 'GO:0048185', 'GO:0016362', 'GO:0070411', 'GO:0019838') # get interesting GOMF cats
>
> # plot the sig GOMF and ancestors
> testG<- GOGraph(GOlist, GOMFPARENTS)
>
> # Put root node on the top, transpose adjacency matrix
> testG<- as(t(as(testG, 'matrix')), 'graphNEL')
>
> #plot the graph (coloured to show sig) with ancestors
>
> # 1. get terms for labels
> theTerms = as.character(sapply(mget(nodes(testG), GOTERM), Term)) #get the terms
> names(theTerms) = nodes(testG) #name the terms
>
> # 2. set up graph parameters
> graph.par(list(nodes=list(label=theTerms, shape='rect', fontsize=36.0), edges=list(lwd=1)))
>
>
> # 3. set up sig node pars
> sigCol<- rep('lightgrey', length(GOlist)) # set a colour for the sigCats
> sigShape<- rep('ellipse', length(GOlist)) # set a shape for the sigCats
> sizeList<- rep(42, length(GOlist)) # set a character size for the sigCats
>
> names(sigCol)<- names(sigShape)<- names(sizeList)<- GOlist # make named lists
>
> #info for the nodes
> width<- rep(14, length(nodes(testG)))#define a custom width
> height<- rep(6, length(nodes(testG)))#define a custom height
> names(width) = names(height) = nodes(testG)#make named vectors
>
> nodeAttrs<- list(label=theTerms, width=width, height=height)#use width&  height for nodes and terms for labels
>
> nodeRenderInfo(testG)<- list(label=theTerms, fill=sigCol, shape=sigShape, width=width, height=height, fontsize=sizeList) # put together in a list of lists
>
> # render the plot
> testLayout<- layoutGraph(testG, layoutType='dot')
> renderGraph(testLayout)
>
>
> best&  thanks
>
> iain
>
>> sessionInfo()
> R version 2.14.2 (2012-02-29)
> Platform: x86_64-pc-linux-gnu (64-bit)
>
> locale:
>   [1] LC_CTYPE=en_GB.utf8       LC_NUMERIC=C
>   [3] LC_TIME=en_GB.utf8        LC_COLLATE=en_GB.utf8
>   [5] LC_MONETARY=en_GB.utf8    LC_MESSAGES=en_GB.utf8
>   [7] LC_PAPER=C                LC_NAME=C
>   [9] LC_ADDRESS=C              LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_GB.utf8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] grid      stats     graphics  grDevices utils     datasets  methods
> [8] base
>
> other attached packages:
> [1] Rgraphviz_1.32.0      GOstats_2.20.0        graph_1.32.0
> [4] Category_2.20.0       GO.db_2.6.1           RSQLite_0.11.1
> [7] DBI_0.2-5             AnnotationDbi_1.16.13 Biobase_2.14.0
>
> loaded via a namespace (and not attached):
>   [1] annotate_1.32.1   genefilter_1.36.0 GSEABase_1.16.0   IRanges_1.12.6
>   [5] RBGL_1.30.1       splines_2.14.2    survival_2.36-12  tools_2.14.2
>   [9] XML_3.9-4         xtable_1.7-0
>>
> 	[[alternative HTML version deleted]]
>
>
>
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at r-project.org
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/



More information about the Bioconductor mailing list