Rgraphviz fontsize
1
1
Entering edit mode
@daniel-jupiter-3011
Last seen 10.2 years ago
Hi all, I'm attempting to use Rgraphviz to do some plotting. There is no problem in producing the plots, but I would like to modify font sizes in the resulting graph, and this appears tricky. The simple fontsize setting in makeNodeAttrs seems to have no effect. There appear to have been some changes to Rgraphviz itself, recently, but I have no concept of how these changes might impact the Ragraph related objects and code. Any suggestions as to how to get fonts to change size, while also setting fixedsize to FALSE? Note: I have looked at documentation for Rgraphviz, and its new interface. I have looked at the old interface as well. And I appear to be lost. Best regards, Dan Jupiter. library(GO.db) library(GOstats) library(KEGG.db) library(annotate) library(org.Rn.eg.db) library("Rgraphviz") library("RBGL") library("graph") library("RColorBrewer") library("geneplotter") library("RbcBook1") # Just some dummy genes to play with. bkg=dbGetQuery(org.Rn.eg_dbconn(), "SELECT * from genes") bkg=bkg$gene_id[1:1000] test=bkg[1:10] # Builds hypergparams object. params <- new("GOHyperGParams", geneIds = test, universeGeneIds = bkg,annotation="org.Rn.eg.db", conditional = FALSE, categoryName="GO", ontology="CC") # Runs the test MyHyperG=hyperGTest(params) # Collect all GO IDs and terms xx <- as.list(GOTERM) GOIDS=0 GOTERMS=0 # Place them into easily accessible arrays. for(i in 1:length(xx)){ GOIDS[i]=GOID(xx[[i]]) GOTERMS[i]=Term(xx[[i]]) } # NEL graph object gGO <- goDag( MyHyperG ) # Graph NEL attributes (node attribute graph object) nAgo <- makeNodeAttrs(gGO, shape="ellipse", label=nodes(gGO), fillcolor = "white" , fontsize=30) # Ragraph object agGO <- agopen(gGO, recipEdges="distinct", layoutType="dot", nodeAttrs=nAgo, name="") # Get node info from Ragraph object and store as agraph node object agNO <- AgNode(agGO) # Color nodes below p-value cutoff for(i in seq(along=agNO)) { # Grab the current node name, nm <- labelText(txtLabel(agNO[[i]])) # Search for that name within the list of pvalues. mn <- match(nm, names(pvalues(MyHyperG))) # Also find the term in the lists of terms and IDs. termMatch=match(nm, GOIDS) # If we've found a match in our pvalue list. if(!is.na(mn)) { # match # If we're below pvalue, color red, otherwise color white. agNO[[i]]@fillcolor <- ifelse( as.vector(pvalues(MyHyperG))[mn] < MyHyperG@pvalueCutoff, "#e31a1c", "#edf8fb") #agNO[[i]]@txtLabel@labelText <- paste(signif(pvalues(MyHyperG)[mn], 2)) # print pvalue node labels # agNO[[i]]@txtLabel@labelText <- substr( names(pvalues(MyHyperG))[mn], 7, 10 ) # print GOid node labels # agNO[[i]]@txtLabel@labelText <- paste(GOIDS[termMatch], "Number of genes", as.character(counter),sep=" ") # If we're below the pvalue, we want the number of genes annotated by the term. if(as.vector(pvalues(MyHyperG))[mn] < MyHyperG@pvalueCutoff){ # This is a list of all gene IDs in the universe annotated by this term. x=gGO@nodeData@data[[i]][1]$geneIds counter=0 for(j in 1:length(x)){ ifis.na(match(x[j], test))){ counter=counter+1 } } # Build the label. agNO[[i]]@txtLabel@labelText <-paste(GOIDS[termMatch], "Number of genes", as.character(counter),sep=" ") } else{ agNO[[i]]@txtLabel@labelText <- GOIDS[termMatch] } } else { # no match agNO[[i]]@fillcolor <- "white" agNO[[i]]@txtLabel@labelText <- "" } } # Update Ragraph object's AgNode slot with agNO agGO@AgNode <- agNO # Plot pdf("~/Desktop/test.pdf", width=20, height=20, paper="special", pagecentre=TRUE) plot(agGO) dev.off() sessionInfo() R version 2.7.1 (2008-06-23) i386-apple-darwin8.10.1 locale: en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] grid splines tools stats graphics [6] grDevices utils datasets methods base other attached packages: [1] RbcBook1_1.8.0 geneplotter_1.18.0 [3] lattice_0.17-8 RColorBrewer_1.0-2 [5] Rgraphviz_1.18.1 org.Rn.eg.db_2.2.0 [7] KEGG.db_2.2.0 GOstats_2.6.0 [9] Category_2.6.0 genefilter_1.20.0 [11] survival_2.34-1 RBGL_1.16.0 [13] annotate_1.18.0 xtable_1.5-2 [15] graph_1.18.1 GO.db_2.2.0 [17] AnnotationDbi_1.2.2 RSQLite_0.6-9 [19] DBI_0.2-4 Biobase_2.0.1 loaded via a namespace (and not attached): [1] KernSmooth_2.22-22 cluster_1.11.11 -- Daniel C. Jupiter, Ph.D. Postdoctoral Research Associate Department of Systems Biology and Translational Medicine College of Medicine Texas A&M Health Science Center 702 SW H.K. Dodgen Loop Temple, TX 76504 979.997.2106 | Fax 254.742.7145 djupiter@tamu.edu | www.tamhsc.edu [[alternative HTML version deleted]]
GO graph Rgraphviz GO graph Rgraphviz • 3.9k views
ADD COMMENT
0
Entering edit mode
@vincent-j-carey-jr-4
Last seen 9 weeks ago
United States
> Hi all, > > I'm attempting to use Rgraphviz to do some plotting. > There is no problem in producing the plots, but I would like to modify font > sizes in the resulting graph, and this appears tricky. > The simple fontsize setting in makeNodeAttrs seems to have no effect. there is a function called pwayRendAttrs in the pathRender package that manipulates graphviz fontsize; plotExG vignette illustrates its use
ADD COMMENT
0
Entering edit mode
Vince, thanks for the tip. Unfortunately I'm not sure how to apply it. The vignette doesn't really make clear to me what it is that pwayRendAttrs does. It is mentioned once, but I'm not exactly clear on its function. It also does not seem to apply to the objects of type that I am using: in my code I have taken my graphNEL object and turned it into an Ragraph object. Am I, as usual, missing something obvious? Dan. On Mon, Sep 8, 2008 at 7:05 PM, Vincent Carey 525-2265 < stvjc@channing.harvard.edu> wrote: > > Hi all, > > > > I'm attempting to use Rgraphviz to do some plotting. > > There is no problem in producing the plots, but I would like to modify > font > > sizes in the resulting graph, and this appears tricky. > > The simple fontsize setting in makeNodeAttrs seems to have no effect. > > there is a function called pwayRendAttrs in the pathRender > package that manipulates graphviz fontsize; plotExG vignette illustrates > its use > -- Daniel C. Jupiter, Ph.D. Postdoctoral Research Associate Department of Systems Biology and Translational Medicine College of Medicine Texas A&M Health Science Center 702 SW H.K. Dodgen Loop Temple, TX 76504 979.997.2106 | Fax 254.742.7145 djupiter@tamu.edu | www.tamhsc.edu [[alternative HTML version deleted]]
ADD REPLY
0
Entering edit mode
> Vince, > > thanks for the tip. > Unfortunately I'm not sure how to apply it. > The vignette doesn't really make clear to me what it is that pwayRendAttrs > does. It is mentioned once, > but I'm not exactly clear on its function. > It also does not seem to apply to the objects of type that I am using: in my > code I have taken my graphNEL object and > turned it into an Ragraph object. > > Am I, as usual, missing something obvious? I don't think so. It seems to be hard to alter the font size much, in the presence of other constraints on node format such as height and width. pwayRendAttrs is used in plotExGraph in pathRender, and one can get some control over node text font size by passing a modified pwayRendAttrs (with altered default AllFontsize) as the attgen parameter to plotExGraph -- not a very elegant arrangement, but one can show that the font sizes can be _reduced_ by doing this. if we do library(graph) library(Rgraphviz) example(randomGraph) plot(g1, nodeAttrs=makeNodeAttrs(g1, fontsize=4)) plot(g1, nodeAttrs=makeNodeAttrs(g1, fontsize=4, fillcolor="green")) we can see that the plotter will respond to the color attribute but not to the fontsize attribute, despite the fact that fontsize is identified in GraphvizAttributes as a target Node Attribute. so either graphviz is misbehaving with respect to font size control or some aspect of communication from R to graphviz needs to be corrected. The fact that you are working with an Ragraph seems to make things a little harder. What I see is that the rendering for Ragraph instances uses drawAgNode which calls drawTxtLabel, and neither seem to make any use of fontsize specs. I used fixInNamespace(drawTxtLabel, "Rgraphviz") to place a cex=2 setting on the text() call that concludes that function, and then plot(agGO) [based on your code] renders the node names quite legibly, but with some collisions. you may be able to tweak the cex setting to get what you want. there is clearly room for improvement in the Rgraphviz interface ... I see some work in the graph package on a renderInfo class that may help with this. Note you can always use getNodeXY, text, and lines (on the BezierCurve objects in the AgEdge) to plot an Ragraph with a desired layout and pretty substantial control over appearance through basic R graphical primitives. A rough sketch is XY = getNodeXY(agGO) plot(XY, bty="n", xlab=" ", ylab=" ", pch= " ", axes=FALSE) text(XY, labels=sapply(agGO at AgNode, "name"), cex=.65) tmp = sapply(AgEdge(agGO), function(x) sapply(x at splines, lines)) > > Dan. > > > > On Mon, Sep 8, 2008 at 7:05 PM, Vincent Carey 525-2265 < > stvjc at channing.harvard.edu> wrote: > > > > Hi all, > > > > > > I'm attempting to use Rgraphviz to do some plotting. > > > There is no problem in producing the plots, but I would like to modify > > font > > > sizes in the resulting graph, and this appears tricky. > > > The simple fontsize setting in makeNodeAttrs seems to have no effect. > > > > there is a function called pwayRendAttrs in the pathRender > > package that manipulates graphviz fontsize; plotExG vignette illustrates > > its use > > > > > > -- > Daniel C. Jupiter, Ph.D. > Postdoctoral Research Associate > Department of Systems Biology and Translational Medicine > College of Medicine > Texas A&M Health Science Center > 702 SW H.K. Dodgen Loop > Temple, TX 76504 > > 979.997.2106 | Fax 254.742.7145 > djupiter at tamu.edu | www.tamhsc.edu > > [[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >
ADD REPLY
0
Entering edit mode
Vince, that works much better, almost perfectly! I used fixInNamespace(drawTxtLabel, "Rgraphviz") , as you suggested. I wasn't aware of this functionality. (Using shape="plaintext" with fixInNameSpace gives essentially the same results as your getNodeXY(agGO) suggestion.) Further, if I maximize the plot, spacing seems to improve quite a bit as well. Nothing will be quite perfect, as I'm actually going to use full GO term names, which can be quite long. Just FYI, if you or anyone else is planning to attempt to resolve some of the communication difficulties with Graphviz/Rgraphviz/Ragraph, I've noticed that I also don't seem to be able to get any reaction to fixedsize=FALSE in nodeAttrs. (Much as with your fontsize experiment.) I haven't tried all the other parameters, but one might guess that there are difficulties there as well, as these seem to be rather subtle issues. Thanks again, it's greatly appreciated. Best regards, Dan. On Mon, Sep 8, 2008 at 11:25 PM, Vincent Carey 525-2265 < stvjc@channing.harvard.edu> wrote: > > > Vince, > > > > thanks for the tip. > > Unfortunately I'm not sure how to apply it. > > The vignette doesn't really make clear to me what it is that > pwayRendAttrs > > does. It is mentioned once, > > but I'm not exactly clear on its function. > > It also does not seem to apply to the objects of type that I am using: in > my > > code I have taken my graphNEL object and > > turned it into an Ragraph object. > > > > Am I, as usual, missing something obvious? > > I don't think so. It seems to be hard to alter the font size much, > in the presence of other constraints on node format such as height and > width. pwayRendAttrs is used in plotExGraph in pathRender, and one > can get some control over node text font size by passing a modified > pwayRendAttrs > (with altered default AllFontsize) as the attgen parameter to plotExGraph > -- > not a very elegant arrangement, but one can show that the font sizes can be > _reduced_ by doing this. > > if we do > > library(graph) > library(Rgraphviz) > example(randomGraph) > plot(g1, nodeAttrs=makeNodeAttrs(g1, fontsize=4)) > plot(g1, nodeAttrs=makeNodeAttrs(g1, fontsize=4, fillcolor="green")) > > we can see that the plotter will respond to the color attribute but > not to the fontsize attribute, despite the fact that fontsize is > identified in GraphvizAttributes as a target Node Attribute. so > either graphviz is misbehaving with respect to font size control or some > aspect of communication from R to graphviz needs to be corrected. > > The fact that you are working with an Ragraph seems to make things > a little harder. What I see is that the rendering for Ragraph instances > uses drawAgNode which calls drawTxtLabel, and neither seem to make > any use of fontsize specs. > > I used fixInNamespace(drawTxtLabel, "Rgraphviz") to place a cex=2 > setting on the text() call that concludes that function, and then > plot(agGO) [based on your code] renders the node names quite legibly, > but with some collisions. you may be able to tweak the cex setting > to get what you want. > > there is clearly room for improvement in the Rgraphviz interface ... > I see some work in the graph package on a renderInfo class that may > help with this. Note you can always use getNodeXY, text, and lines > (on the BezierCurve objects in the AgEdge) to plot an Ragraph with a > desired layout and pretty substantial control over appearance through > basic R graphical primitives. A rough sketch is > > XY = getNodeXY(agGO) > plot(XY, bty="n", xlab=" ", ylab=" ", pch= " ", axes=FALSE) > text(XY, labels=sapply(agGO@AgNode, "name"), cex=.65) > tmp = sapply(AgEdge(agGO), function(x) sapply(x@splines, lines)) > > > > > > Dan. > > > > > > > > On Mon, Sep 8, 2008 at 7:05 PM, Vincent Carey 525-2265 < > > stvjc@channing.harvard.edu> wrote: > > > > > > Hi all, > > > > > > > > I'm attempting to use Rgraphviz to do some plotting. > > > > There is no problem in producing the plots, but I would like to > modify > > > font > > > > sizes in the resulting graph, and this appears tricky. > > > > The simple fontsize setting in makeNodeAttrs seems to have no effect. > > > > > > there is a function called pwayRendAttrs in the pathRender > > > package that manipulates graphviz fontsize; plotExG vignette > illustrates > > > its use > > > > > > > > > > > -- > > Daniel C. Jupiter, Ph.D. > > Postdoctoral Research Associate > > Department of Systems Biology and Translational Medicine > > College of Medicine > > Texas A&M Health Science Center > > 702 SW H.K. Dodgen Loop > > Temple, TX 76504 > > > > 979.997.2106 | Fax 254.742.7145 > > djupiter@tamu.edu | www.tamhsc.edu > > > > [[alternative HTML version deleted]] > > > > _______________________________________________ > > Bioconductor mailing list > > Bioconductor@stat.math.ethz.ch > > https://stat.ethz.ch/mailman/listinfo/bioconductor > > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > > > -- Daniel C. Jupiter, Ph.D. Postdoctoral Research Associate Department of Systems Biology and Translational Medicine College of Medicine Texas A&M Health Science Center 702 SW H.K. Dodgen Loop Temple, TX 76504 979.997.2106 | Fax 254.742.7145 djupiter@tamu.edu | www.tamhsc.edu [[alternative HTML version deleted]]
ADD REPLY

Login before adding your answer.

Traffic: 467 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6