E Print ASCII-art rooted tree

library(data.tree)
tree <- rtree(10)
d <- as.data.frame(as.Node(tree))
names(d) <- NULL
print(d, row.names=FALSE)
                       
 11                    
  ¦--12                
  ¦   ¦--13            
  ¦   ¦   ¦--t4        
  ¦   ¦   °--t6        
  ¦   °--t10           
  °--14                
      ¦--15            
      ¦   ¦--16        
      ¦   ¦   ¦--17    
      ¦   ¦   ¦   ¦--t5
      ¦   ¦   ¦   °--t7
      ¦   ¦   °--t2    
      ¦   °--18        
      ¦       ¦--t1    
      ¦       °--t9    
      °--19            
          ¦--t3        
          °--t8        

It is neat to print ASCII-art of phylogeny. Sometimes we don’t want to plot the tree, but just take a glance at the tree structure without leaving the focus from R console. However, it is not a good idea to print the whole tree as ASCII text if the tree is large. Sometimes we just want to look at a specific portion of the tree and their immediate relatives. At this scenario, we can use treeio::tree_subset() function (see session 2.4) to extract selected portion of a tree. Then we can print ASCII-art of the tree subset to explore evolutionary relationship of interested species in R console.

ggtree supports parsing tip labels as emoji to create phylomoji. With the data.tree and emojifont packages, we can also print phylomoji as ASCII text.

library(emojifont)

tt <- '((snail,mushroom),(((sunflower,evergreen_tree),leaves),green_salad));'
tree <- read.tree(text = tt)
tree$tip.label <- emoji(tree$tip.label)
d <- as.data.frame(as.Node(tree))
names(d) <- NULL
print(d, row.names=FALSE)
                  
 7                
  ¦--8            
  ¦   ¦--🐌        
  ¦   °--🍄        
  °--9            
      ¦--10       
      ¦   ¦--11   
      ¦   ¦   ¦--🌻
      ¦   ¦   °--🌲
      ¦   °--🍃    
      °--🥗        

Another way to print ASCII-art pf phylogeny is to use the ascii() device defined in devout package. Here is an example:

library(devout)
ascii(width=80)
ggtree(rtree(5))
invisible(dev.off())
                                                                                
                                                   ########################     
                                                   #                            
                           #########################                            
                           #                       #                            
                           #                       #########################    
       #####################                                                    
       #                   #                                                    
       #                   #                                                    
   #####                   ###############                                      
   #   #                                                                        
   #   #                                                                        
   #   #                                                                        
   #   #########                                                                
   #                                                                            
   #                                                                            
   #                                                                            
   #############