Hi,
I'm trying to reproduce Example 2 in the ggtree paper with my own tree produced in PAUP and stored in nexus format. My code looks like this:
>rm(list=ls())
>library(ggtree)
>library(ape)
>tree <- read.nexus('mytree.tre')
>tree
Phylogenetic tree with 840 tips and 839 internal nodes.
Tip labels:
A, B, C, D, E, F, ...
Rooted; includes branch lengths.
>ggtree(tree,aes(color=tree$edge.length))+
+ theme_tree2()+
+ scale_color_continuous(high='#D55E00',low='#0072B2')+geom_tiplab(size=2)
Error: Aesthetics must be either length 1 or the same as the data (1679): node, parent, x, y, colour
It's is clear that ggtree is assuming there is one additional edge that doesn't exists in the tree:
>length(tree$edge.length)
[1] 1678
> nrow(tree$edge)
[1] 1678
But I can't figure out why. I've tried rerunning the code after converting the tree to Newick format and also unrooting the tree to no avail. The code runs successfully if I add one 'fictional' length (something like aes(color=c(tree$edge.length,1)),) but, since I don't know where that "1"is being landed, I'm sure I'll end up shooting myself in the foot.
I noticed also that the error message disappears if data is made explicit as in the following script, but the printed tree turns to be completely black, which is pointless
ggtree(data=tree,aes(color=edge.length))+
theme_tree2()+
scale_color_continuous(high='#D55E00',low='#0072B2')+geom_tiplab(size=2)
Is there an explanation for this? A bug maybe? How can I solve this issue?
Side note: get.fields also produces an error
> get.fields(tree)
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘get.fields’ for signature ‘"phylo"’