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