Is ggtree miscounting the number of edges?

725 views
Skip to first unread message

jeama...@gmail.com

unread,
Oct 18, 2016, 9:58:32 AM10/18/16
to ggtree
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"’

Yu, Guangchuang

unread,
Oct 18, 2016, 9:21:41 PM10/18/16
to jeama...@gmail.com, ggtree
You are using ggtree in the wrong way.




For first issue, you code should be:

ggtree(tree,aes(color=branch.length))+

  theme_tree2
()+
  scale_color_continuous
(high='#D55E00',low='#0072B2')+geom_tiplab(size=2)


For the second issue, get.fields is S4 method for getting features available in S4 tree objects that contains tree and associated data (features).

phylo is only designed for storing tree but not with associated data, and there is no get.fields method for it.


--
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+unsubscribe@googlegroups.com.
To post to this group, send email to bioc-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bioc-ggtree/8a457f97-a555-423e-9e9d-50c3b5577dc6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
--~--~---------~--~----~------------~-------~--~----~
Guangchuang Yu, PhD Candidate
State Key Laboratory of Emerging Infectious Diseases
School of Public Health
The University of Hong Kong
Hong Kong SAR, China
-~----------~----~----~----~------~----~------~--~---
Reply all
Reply to author
Forward
0 new messages