[BioC] two-line labels in GO graphs
Brian D. Peyser, Ph.D.
news at bpeyser.fastmail.net
Thu Jun 26 17:49:19 CEST 2008
Robert Castelo <robert.castelo at ...> writes:
<snip>
> the newline character '\n' i was giving to the separator 'sep' parameter
> in the paste function should be written as '\\\n'. doing it this way my
> former example works:
>
> library(GOstats)
> library(Rgraphviz)
>
> goterms <- eapply(GOTERM,Term)
> g <- GOGraph("GO:0016265",GOBPPARENTS)
> g <- removeNode("all",g)
> mt <- match(nodes(g),names(goterms))
> nodattr <- makeNodeAttrs(g,label=paste(nodes(g),goterms[mt],sep="\\\n"),
> shape="ellipse",fillcolor="#f2f2f2",
> fixedsize=FALSE)
> plot(g,nodeAttrs=nodattr)
>
> ... and no, writing '\\n' doesn't work.
>
<snip>
Thankyouthankyouthankyouthankyouthankyou!
Spent about 4 hours trying to get multi-line labels, trying from one to four
backslashes. Finally I searched the help archive and found your solution. In my
case, I wanted to split up long lines, so I was using gsub():
tmpGraphAttrs$nodeAttrs$label <- gsub("([[:print:]]{10})[[:space:]]",
"\\1\\\\\n", tmpGraphAttrs$nodeAttrs$label)
In that case, I had to use _five_ backslashes to get what I was after! (Escape
the first backslash, escape the second backslash, then \n.)
--which results in something like this:
tmpGraphAttrs$nodeAttrs$label[1]
GO:0009605
"response to\\\nexternal stimulus"
So the node label string itself must have a triple-backslashed 'n' for a
functional newline, which requires even more backslashing in (g)sub. I had been
trying to get either '\n' or '\\n' in the string, but hadn't realized that I
need '\\\n' for it to work.
Thanks again!
-Brian Peyser
news at at@bpeyser.dot.fastmail.dot.net
(use your biological supercomputer to fix that before replying)
More information about the Bioconductor
mailing list