2014-04-02 16 views
0

您好,我擁有深度測序數據的系統發生樹。問題是許多序列是相同的,所以我想讓那些具有x個相同序列的節點由一個大小爲x的圓圈表示。這在R中使用APE包很容易完成。問題是我有兩組不同顏色的序列。因此,例如,在節點1,30%的相同序列來自組1,70%來自組2.理想情況下,節點上的這些圓實際上是餅圖,顯示不同的表示,但我無法弄清楚如何計算矢量喂猿。有任何想法嗎?使用ape在R中繪製相同的序列

+1

你我們可以使用一些可重複使用的小數據(代表您的概率LEM)?還有一些代碼可以使你當前的圖形(再次簡化爲我們需要的再現你的圖形),所以我們有一個開始的地方? –

回答

1

用一個簡單的例子:

owl <- read.tree(text="owls(((Strix_aluco:4.2,Asio_otus:4.2):3.1,Athene_noctua:7.3):6.3,Tyto_alba:13.5);") 
piedata <- cbind(c(10,50,75),c(90,50,25)) 

你需要的是:

1)要知道節點
2)的座標能夠繪製現有的情節

內部餅圖

對於第一部分,plot.phylo保存在內存中使用的座標:

plot(owl) 
owl.info <- get("last_plot.phylo", envir = .PlotPhyloEnv) 
str(owl.info) 
List of 20 
$ type   : chr "phylogram" 
$ use.edge.length: logi TRUE 
$ node.pos  : num 1 
$ show.tip.label : logi TRUE 
$ show.node.label: logi FALSE 
$ font   : num 3 
$ cex   : num 1 
$ adj   : num 0 
$ srt   : num 0 
$ no.margin  : logi FALSE 
$ label.offset : num 0 
$ x.lim   : num [1:2] 0 17.7 
$ y.lim   : num [1:2] 1 4 
$ direction  : chr "rightwards" 
$ tip.color  : chr "black" 
$ Ntip   : int 4 
$ Nnode   : int 3 
$ edge   : int [1:6, 1:2] 5 6 7 7 6 5 6 7 1 2 ... 
$ xx    : num [1:7] 13.6 13.6 13.6 13.5 0 6.3 9.4 
$ yy    : num [1:7] 1 2 3 4 3.12 ... 

xxyy是tips +節點的座標(它們的編號對應於phylo對象的edge元素中的編號)。在這裏,我們的內部節點是節點5到7.
對於第二點包plotrix帶有一個方便的floating.pie函數。

所以在這裏:

plot(owl) 
owl.info <- get("last_plot.phylo", envir = .PlotPhyloEnv) 
for(i in 1:nrow(piedata)){ 
    floating.pie(owl.info$xx[4+i], 
       owl.info$yy[4+i], 
       piedata[i,], 
       col=c("red","blue"), 
       xpd=TRUE) 
    } 

enter image description here

此外,如果你想根據變量x改變餅圖的大小:

x <- c(3,6,2) 
plot(owl) 
owl.info <- get("last_plot.phylo", envir = .PlotPhyloEnv) 
for(i in 1:nrow(piedata)){ 
    floating.pie(owl.info$xx[4+i], 
       owl.info$yy[4+i], 
       piedata[i,], 
       radius=x[i]/5 
       col=c("red","blue"), 
       xpd=TRUE) 
    } 

enter image description here

+0

哇,真是太棒了!正是我期待的!謝謝! – user3487289