General difficulties and confusion with object types

604 views
Skip to first unread message

Andy

unread,
Oct 6, 2020, 12:17:43 PM10/6/20
to ggtree

Hello,

I did my best to relearn what I could from R basics and ggplot.  But I am still having issues with functions and syntax in ggtree, and I think it's because I am not quite understanding everything regarding object types and what ggtree does and does not do.  I am not an advanced R user, but here's what I figured out on my own (followed by my problems):

1. using the read.XXX functions (read.raxml in my case), a tree is called into the R environment (parsed?)
ex: tree <- read.raxml(PATH-TO-FILE)

this is a "phylo" class object

2. using the ggtree(tree) function converts the object to a tree object and it is plotted. You can update this with various geom objects to create a nice looking plot

3. you can store this ggtree() + geom_ object inside a variable
ex: p <- ggtree(tree) + geom_text2()

this object remains a "ggtree" object

What I can't figure out:

1.  How do I rotate a branch with rotate()? When I try p2 <- rotate(p,  59) I get the error "Error in rotate(p, 59): object "phy" is not of class "phylo".

So, I tried:
tree <- read.raxml("RAxML_bipartitionsBranchLabels.tree")
tree <- as.phylo(tree)
ggtree(tree) + geom_text2(aes(subset=!isTip, label=node)) + geom_tiplab()
rootedTree <- phytools::reroot(tree, 48)
is.rooted(rootedTree)
rootedTree <- rotate(tree, 49)
p <- ggtree(rootedTree, branch.length = "none") + geom_text2(aes(subset=!isTip, label=node)) + geom_tiplab() + xlim(0,25)
p

And the tree didn't seem to rotate the branch I wanted. I managed to rotate a branch once, but I don't know how....

2. I try many functions that return an error that says I can't use an S3 object type. In short, how do I know when a function will accept an S3 object type, and what should I do if I can't get the function to do what I want?

In general, I am lost in my workflow and don't know when I should be "updating" a plot by ggtree or when I should go back to the beginning where the original tree file was read by read.raxml(), and I'm not quite sure of the difference between plotting with the ggtree() function or plotting by:

p <- ggtree(tree)
p

Any general advice on this would be immensely helpful...

Kind Regards,

Andy

Andy

unread,
Oct 6, 2020, 12:19:38 PM10/6/20
to ggtree
PS - here is a list of my libraries at the beginning of my session:

library("tidyverse")
library("ggplot2")
library("ggtree")
library("ape")
library("treeio")
library("colorspace")
library("cowplot")
library("phytools")
library("Biostrings")
library("ggstance")
library("stringr")

Yu, Guangchuang

unread,
Oct 10, 2020, 11:27:13 AM10/10/20
to Andy, ggtree

This is due to function conflict. Using ggtree::rotate should works

--
1. G Yu*. Using ggtree to visualize data on tree-like structures. Current Protocols in Bioinformatics. 2020, 69:e96. https://doi.org/10.1002/cpbi.96
2. LG Wang, TTY Lam, S Xu, Z Dai, L Zhou, T Feng, P Guo, CW Dunn, BR Jones, T Bradley, H Zhu, Y Guan, Y Jiang, G Yu*. treeio: an R package for phylogenetic tree input and output with richly annotated and associated data. Molecular Biology and Evolution. 2020, 37(2):599-603. http://dx.doi.org/10.1093/molbev/msz240
3. G Yu*, TTY Lam, H Zhu, Y Guan*. Two methods for mapping and visualizing associated data on phylogeny using ggtree. Molecular Biology and Evolution, 2018, 35(2):3041-3043. https://doi.org/10.1093/molbev/msy194
4. G Yu, DK Smith, H Zhu, Y Guan, TTY Lam*. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data, Methods in Ecology and Evolution, 2017, 8(1):28-36. https://doi.org/10.1111/2041-210X.12628
5. Book: https://yulab-smu.top/treedata-book/
---
You received this message because you are subscribed to the Google Groups "ggtree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bioc-ggtree...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bioc-ggtree/89d8e0fb-fc9d-41bc-8bda-421d510a4053n%40googlegroups.com.


--
--~--~---------~--~----~------------~-------~--~----~
Guangchuang Yu PhD
Professor, Associate Director
Department of Bioinformatics
School of Basic Medical Sciences
Southern Medical University
Guangzhou, China
-~----------~----~----~----~------~----~------~--~---
Reply all
Reply to author
Forward
0 new messages