bootstrap values from newick format

1,784 views
Skip to first unread message

Kirston Barton

unread,
Apr 11, 2016, 8:27:51 PM4/11/16
to ggtree
HI, I am trying to add bootstrap values from a newick file. Some searches on the internet have turned up the following code, but the values are displayed as decimals. Is there any way to multiply the number by 100 and have it cut off at the decimal point so 0.909 would show up as 91. I am also having trouble getting the numbers to display nicely at the node (i.e., rotated along the line and not overlapping other parts of the image). Here is my code:

tg = ggtree(t, layout = "circular", size = .1) 
p <- tg + geom_tippoint(aes(x=x+.003, subset=(abs(angle) >= 90), angle=angle+180), fill=Fill, color=Outline, shape=Shape, size=4, stroke = .1) + xlim(-.1, .15)
q <- p + geom_treescale(x=0.05, width=.005, color='red')
r <- q + geom_text2(aes(label=label, subset=label>.07 & !isTip), hjust=-.2)
r

and the resulting tree is attached.

Other than these minor issues, I am getting close to what we want for our final product. Thank you for putting this all together!

Kind regards,
Kirston

Rplot05.pdf
Message has been deleted
Message has been deleted

gc...@connect.hku.hk

unread,
Apr 11, 2016, 9:55:42 PM4/11/16
to ggtree
You can directly convert the number in `aes`.

For example:

library(ggtree)
raxml_file <- system.file("extdata/RAxML", "RAxML_bipartitionsBranchLabels.H3", package="ggtree")
raxml <- read.raxml(raxml_file)
ggtree(raxml)+ geom_text(aes(label=bootstrap/100))


But in your case, the bootstrap value is stored in node label, which should be stored in character, I recommend you converting it outside ggtree and then using the tidy data to label the bootstrap.

d = q$data
d=d[!d$isTip,]
d$label = as.numeric(d$label)
d$label = round(d$label * 100)
d=d[d$label > 70,]

q + geom_text2(data=d, aes(label=label), hjust=-.2)

Kirston Barton

unread,
Apr 12, 2016, 8:17:02 PM4/12/16
to ggtree
Thank you, this is working very well. I think it is the last piece of of the puzzle. Our trees are looking pretty good! Thank you for all of your help.
Reply all
Reply to author
Forward
0 new messages