[英]plotting identical sequences in R using ape
您好,我有深度測序數據的系統樹。 問題是許多序列是相同的,所以我想用x大小的圓表示具有x個相同序列的節點。 使用APE包在R中很容易做到這一點。 問題是我有兩組要改變顏色的序列。 因此,例如在節點1上,相同序列的30%來自組1,而70%來自組2。理想情況下,節點上的這些圓圈實際上是餅圖,顯示了不同的表示形式,但我無法弄清楚如何計算媒介喂養猿。 有任何想法嗎?
用一個簡單的例子:
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 ...
xx
和yy
是phylo
+ nodes的坐標(它們的編號與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)
}
此外,如果要根據變量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)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.