Ggtree drawing high-end evolutionary tree

Time:2022-5-5

Phylogenetic tree is almost a necessary map for gene family articles. A good-looking tree map can really add a lot of color to the article. Ordinary users may only use Mega drawing, and those who are more advanced will use two online drawing platforms such as itol and evolview. However, this is not the focus of this article. This section introduces how to use itggtreeTo map the phylogenetic tree sinceggtreeEvolutionary tree mapping has never been so simple

Ggtree drawing high-end evolutionary tree

Load R package

library(tidyverse)
library(ggtree)
library(treeio)
library(ggsci)

read in data

node. Label = “support” parse the node label into support value and save it as tree annotation data

tree <- read.newick("tree.nwk",node.label = "support")
group <- read.table("group.xls",header = T,row.names = 1)
group1 <- split(row.names(group),group$Group)

Data visualization

Draw the trunk of the tree first

p <- groupOTU(tree,group1) %>%
  ggtree(branch.length = "none",
         linetype=1,size=0.8,ladderize = T,aes(color=group))

p

Ggtree drawing high-end evolutionary tree

Add a background color to the group according to the node information

p1 <- p + geom_text(aes(label=node), hjust=-3,size=3)+
  scale_color_nejm()+labs(color="")+
  geom_hilight(node=63,fill="#1E90FF",type="rect",alpha=0.6)+
  geom_hilight(node=36,fill="#FF8C00",type="rect",alpha=0.6)+
  geom_hilight(node=43,fill="#4DAF4A",type="rect",alpha=0.6)+
  geom_hilight(node=47,fill="#984EA3",type="rect",alpha=0.6)

Ggtree drawing high-end evolutionary tree

Add confidence information

p2 <- p1 + geom_point2(aes(subset=!isTip,
fill=support),shape=21,size=2)+
  scale_fill_continuous(low='green',high='red')

Ggtree drawing high-end evolutionary tree

Draw grouped color bars according to nodes. There are many parameters here. There is no need to adjust them all first. Just determine the start and end points of the color bars, because we need to convert them into circles later

p3 <- p2 + geom_strip(62,49,label = "Group I", align = T, alpha=.8,family="Times",
             fontsize=5,offset = 7, color = "#984EA3",offset.text = 2 ,
             hjust="center",barsize = 5,extend = 1)+
  geom_strip(44,46,label = "Group II", align = T, alpha=.8,family="Times",
             fontsize=5,offset = 7, color ="#4DAF4A",offset.text = 2 ,
             hjust="center",barsize = 5,extend = 1,angle=66)+
  geom_strip(40,1,label = "Group III", align = T, alpha=.8,family="Times",
             fontsize=5,offset = 7, color = "#FF8C00",offset.text = 2 ,
             hjust="center",barsize = 5,extend = 1,angle=0)+
  geom_strip(63,66,label = "Group V", align = T, alpha=.8,family="Times",
             fontsize=5,offset = 7, color = "#1E90FF",offset.text = 2 ,
             hjust="center",barsize = 5,extend = 1,angle=-50)

Ggtree drawing high-end evolutionary tree

After the above steps, we have obtained the location information of adding background and color bar to the group. Let’s show the graphic layout as a circle from the beginning

Full version code

pp3 <- groupOTU(tree,group1) %>%
  ggtree(branch.length = "none",layout = "circular",
         linetype=1,size=0.8,ladderize = T,aes(color=group))+
  #geom_text(aes(label=node), hjust=-3,size=3) +
  geom_tiplab(size=3,family="Times",hjust = -0.1)+
  scale_color_nejm()+labs(color="")+
  geom_hilight(node=63,fill="#1E90FF",type="rect",alpha=0.6)+
  geom_hilight(node=36,fill="#FF8C00",type="rect",alpha=0.6)+
  geom_hilight(node=43,fill="#4DAF4A",type="rect",alpha=0.6)+
  geom_hilight(node=47,fill="#984EA3",type="rect",alpha=0.6)+
  geom_point2(aes(subset=!isTip,fill=support),shape=21,size=2)+
  scale_fill_continuous(low='green',high='red')+
  geom_strip(62,49,label = "Group I", align = T, alpha=.8,family="Times",
             fontsize=5,offset = 7, color = "#984EA3",offset.text = 2 ,
             hjust="center",barsize = 5,extend = 1)+
  geom_strip(44,46,label = "Group II", align = T, alpha=.8,family="Times",
             fontsize=5,offset = 7, color ="#4DAF4A",offset.text = 2 ,
             hjust="center",barsize = 5,extend = 1,angle=66)+
  geom_strip(40,1,label = "Group III", align = T, alpha=.8,family="Times",
             fontsize=5,offset = 7, color = "#FF8C00",offset.text = 2 ,
             hjust="center",barsize = 5,extend = 1,angle=0)+
  geom_strip(63,66,label = "Group V", align = T, alpha=.8,family="Times",
             fontsize=5,offset = 7, color = "#1E90FF",offset.text = 2 ,
             hjust="center",barsize = 5,extend = 1,angle=-50)+
  labs(fill = "bootstrap")
ggsave(pp3,file="tree.png",width =8,height =7,units="in",dpi=300)

pp3

Ggtree drawing high-end evolutionary tree
library(ggpubr)
Tibble (function = C ("geom_strip", "geom_tiplab()", "geom_fruit()",
             "offset.text","extend","offset","hjust=center"),
         Function = C ("add external strip according to node, followed by node location information", 
               "Set label display", "draw bar", "adjust label position",
               "Adjust spacing between strips", "set position of distance node", "center label")% >%
  ggtexttable(rows = NULL, theme = ttheme("mBlue"))
Ggtree drawing high-end evolutionary tree

File link:https://mp.weixin.qq.com/s/icdgysLduSd2Q61HSDKhJg