2016-03-15 197 views
2

我正在嘗試使用ggtree創建系統發育樹。我無法調整樹的中心大小,因此表示我的序列的邊上的符號不重疊並增加了半徑,因此分支長度不夠長。任何意見或提示如何做到這一點將不勝感激。 在此先感謝!ggtree更改半徑尺度

我使用下面的腳本來創建樹...

ggtree(PhyMLAATree, layout = "circular") + 
    geom_tippoint(aes(x=x+.01), shape=Shape, fill=Fill, size=3) 

這兩個圖像顯示什麼,我創造什麼,我想創建。 樹找出來如下: This is how the output looks

想最後的樹看起來更像這有一個更大的中心: This is how I would like the tree to look

我試圖與更多的空間分配裝置,但我得到的在樹(石英相同的比例(寬度= 12,高度= 12)

回答

0

在我的方法我重新創建的邊緣的長度,以下從內到外邊緣通過分層級別的負指數分佈。

library(ggtree) # install as in: 
#source("https://bioconductor.org/biocLite.R") 
#biocLite("ggtree") 
library(data.tree) 
library(gridExtra) 
library(rlist) 
library(phangorn) 

#create random tree 
tree<-ape::rtree(251) 
#its plot 
originalplot<-ggtree(tree, layout="circular")+ geom_tiplab2() + labs(title="original tree") + 
    theme(plot.title = element_text(hjust = 0.5)) 

transformtree<-function(tree,radialparameter,repeatparameter,tiplength){ 
    # radialparameter # # change this to collapse less(0.5) or more (3) and modify repeatparameter together 
    # repeatparameter # # i.e. increase if there are very small branches (levels) 
    #number of hierarchical levels in tree 
    dfr0<-as.data.frame(tree$edge) 
    tree2<-FromDataFrameNetwork(dfr0)# data.tree package 
    levels<-ToDataFrameTable(tree2, "level") 
    edgelevels<-max(levels)-1 
    # establish the hierarchy of nodes looking for the children of the children nodes 
    centralnode<-getMRCA(tree,1:length(tree$tip.label)) 
    childrenlist<-list() 
    childrenlist[1]<-list(phangorn::Children(tree, centralnode)) 
    for (i in 2:edgelevels){ 
    childrenlist[i]<- list(unlist(lapply(unlist(childrenlist[i-1]), function(x) phangorn::Children(tree, x)))) 
    } 
    # remove nodes of tips, we do not want to modify their length 
    childrentipsremoved<-lapply(childrenlist, function(x) x[!is.element(x,1:length(tree$tip.label))]) 
    # list of inner nodes 
    groupedinnernodes<-rlist::list.clean(childrentipsremoved, fun = function(x) length(x) == 0L) 
    #this is the vector that will multiply the inner edges 
    transfvector<- rep(((c(1:(length(groupedinnernodes)/repeatparameter))^(-radialparameter))*5), 
        each=repeatparameter) 
    # check length of groups of inner nodes and the transformation vector 
    lengths<-unlist(lapply(groupedinnernodes, function(x) length(x))) 
    if(length(lengths)-length(transfvector)>0) { 
    for (i in 1:abs(length(lengths)-length(transfvector)) ){ 
     transfvector <- c(transfvector,transfvector[length(transfvector)]) 
    } } 
    if(length(lengths)-length(transfvector)<0) { 
    for (i in 1:abs(length(lengths)-length(transfvector)) ){ 
     transfvector <- transfvector[-1] }} 
    # create the factor to transform the inner edges 
    vector1<-unlist(mapply(rep, transfvector,lengths)) 
    # discard length info, replace all edge length information by 1 
    size<-length(tree$edge.length) 
    tree$edge.length<-rep(1,size) 
    # replace edge length for the connecting inner nodes only 
    innernodes<-unlist(groupedinnernodes) 
    tree$edge.length[unlist(lapply(innernodes,function(x,y) which(y==x),y=tree$edge[,2]))]<- 
    tree$edge.length[unlist(lapply(innernodes,function(x,y) which(y==x),y=tree$edge[,2]))]* 
    vector1 
    # modify length of tip edges # optional decrease for big trees 
    tree$edge.length[tree$edge.length==1]<-tiplength 
    return(tree) 
} 

tree<-transformtree(tree,2.5,2,0.2) 
# plot of modified tree aligned tips 
newplot<-ggtree(tree, layout="circular")+ geom_tiplab2(align=T,linetype=1, linesize=.02, 
                 size=1.8, offset=0.5) + labs(title="modified tree align=T")+ 
    theme(plot.title = element_text(hjust = 0.5)) 

# plot of modified tree not aligned tips 
newplot2<-ggtree(tree, layout="circular")+ geom_tiplab2(align=F,linetype=1, linesize=.02, 
                 size=1.8, offset=0.5) + labs(title="modified tree align=F")+ 
    theme(plot.title = element_text(hjust = 0.5)) 

#plots 
gridExtra::grid.arrange(originalplot,newplot,newplot2,ncol=2) 

enter image description here