F1000_workflow icon indicating copy to clipboard operation
F1000_workflow copied to clipboard

Scale bar for tree using phangorn and phyloseq

Open AMFBio opened this issue 6 years ago • 2 comments

Hi there,

I'm trying to get a scale bar for my phlyogenetic tree.

I’m using the instructions found in this tutorial: https://f1000research.com/articles/5-1492/v2

After I process my sequences and run the alignment, my script is as follows:

phang.align <- phyDat(as(alignment, "matrix"), type="DNA") dm <- dist.ml(phang.align) treeNJ <- NJ(dm) fit = pml(treeNJ, data=phang.align) negative edges length changed to 0! fitGTR <- update(fit, k=4, inv=0.2) fitGTR <- optim.pml(fitGTR, model="GTR", optInv=TRUE, optGamma=TRUE, rearrangement = "stochastic", control = pml.control (trace = 0))

I combine this into my phyloseq object, then I filter and prune my data set to give me the new phyloseq object: test15_2

I plot this tree using:

plot_tree(test15_2, color="Species", ladderize="left", label.tips=labeltips)

But I’m unsure of how to add the scale bar in here?

Any help would be appreciated.

Cheers,

AMFBio avatar Jun 02 '19 21:06 AMFBio

Hi @AMFBio . I'm wondering if by any chance did you find a way to add a scale bar using phyloseq?

papelypluma avatar Oct 31 '20 07:10 papelypluma

Better late than never. Sharing what I found and eventually used to generate a scale bar. The library ggtree does the job, although importing the library may generate unusual warnings along the way (I surmise they can be safely ignored). In brief, a scale bar can be generated by appending geom_treescale(x=int, y=int, fontsize=int, linesize=int, offset=int, color='str') to the plot_tree()/ggplot object. The arguments specified in x, y and offset will tell how the scale bar is positioned relative to the tree.

papelypluma avatar Nov 19 '20 02:11 papelypluma