简体   繁体   English

使用 ape 包中的 nodelables 时出现 float.pie 错误

[英]floating.pie error while using nodelables from ape package

I get an error while using the ARD model of the ace function in R. The error is在 R 中使用 ace 函数的 ARD 模型时出错。错误是

Error in floating.pie.asp(XX[i], YY[i], pie[i, ], radius = xrad[i], col = piecol) : floating.pie: x values must be non-negative float.pie.asp(XX[i], YY[i], pie[i, ], radius = xrad[i], col = piecol) 中的错误:floating.pie:x 值必须为非负

library(ape)
library(phylobase)
tree <- read.nexus("data1.nexus")
plot(tree)
data <- read.csv("phagy_species.csv")
clade.full <- extract.clade(tree, node=91)
plot(clade.full)
clade.1 <- drop.tip(clade.full, "Bar_bre")
clade.2<- drop.tip(clade.1, "Par_pho")
clade.3<- drop.tip(clade.2, "Par_iph")
clade.4<- drop.tip(clade.3, "Eur_ser")
clade.5<- drop.tip(clade.4, "Opo_sym")
clade.6<- drop.tip(clade.5, "Mor_pel")
clade.7<- drop.tip(clade.6, "Aph_hyp")
clade.8<- drop.tip(clade.7, "Ere_oem")
clade.9<- drop.tip(clade.8, "Cal_bud")
clade.10<- drop.tip(clade.9, "Lim_red")
clade.11<- drop.tip(clade.10, "Act_str")
clade.12<- drop.tip(clade.11, "Hel_hec")
clade.13<- drop.tip(clade.12,"Col_dir")
clade.14<- drop.tip(clade.13, "Hyp_pau")
clade.15<- drop.tip(clade.14, "Nym_pol")
clade.16<- drop.tip(clade.15, "Mel_cin")
clade.17<- drop.tip(clade.16,"Apa_iri")
clade.18<- drop.tip(clade.17, "Bib_hyp")
clade.19<- drop.tip(clade.18, "Mar_ors")
clade.20<- drop.tip(clade.19, "Apo_cra")
clade.21<- drop.tip(clade.20, "Pse_par")
clade.22 <- drop.tip(clade.21, "Lep_sin")
clade.23<- drop.tip(clade.22, "Dis_spi")
plot(clade.23)
data2 <- as.numeric(data[,2])
model2 <- ace(data2, clade.23, type="discrete", method="ML", model="ARD")
summary(model2)
d <-logLik(model2)
deviance(model2)
AIC(model2)
plot(clade.23, type="phylogram", cex=0.8, font=3, label.offset = 0.004)
co <- c("red", "blue", "green", "black")
nodelabels(pie = model2$lik.anc, piecol = co, cex = 0.5)

And that is when I get the error.那就是我收到错误的时候。 There is no error if I use the original tree without trimming.如果我在不修剪的情况下使用原始树,则没有错误。 But, when i trim them to my requirements, it goes in the negative.但是,当我根据我的要求修剪它们时,结果是否定的。

Here is the data tree file这是数据树文件

data file 数据文件

The matrix you are using for the proportions of the pie has complex numbers in it.您用于饼图比例的矩阵中有复数。 To see this, try:要看到这一点,请尝试:

class(model2$lik.anc[1,1])

The rows of that matrix define the proportions of the pies, and they need to sum to 1. Your code produces a plot with pies if I replace the pie matrix in the nodelabels function like this:该矩阵的行定义了饼图的比例,它们的总和需要为 1。如果我像这样替换nodelabels函数中的饼图矩阵,您的代码会生成一个饼图:

nodelabels(pie = matrix(0.25, 64, 4), piecol = co, cex = 0.5)

because now there is a legitimate matrix for the pie argument with rows that sum to 1.因为现在pie参数有一个合法的矩阵,其中的行总和为 1。

As for why you have complex numbers in that matrix, I am not sure.至于为什么你在那个矩阵中有复数,我不确定。 It is probably related to all the warnings produced by the ace in your example.它可能与您示例中的ace产生的所有警告有关。 But that is a completely different issue.但这是一个完全不同的问题。

I had the same problem with my data.我的数据也有同样的问题。 I put my data into the matrix (like Slow Ioris suggested) and then unlisted the matrix.我将我的数据放入矩阵中(如 Slow Ioris 建议的那样),然后将矩阵取消列出。

x <- matrix(data=c(model2$lik.anc[,1],model2$lik.anc[,2],model2$lik.anc[,3],model2$lik.anc[,4]))
plotTree(tree,ftype="i",label.offset = 0.02)
nodelabels(pie = unlist(x))

对于在清除数据的可想象部分后也遇到相同问题的其他人:当您向pie提供 data.frame 而不是矩阵时, nodelabels 函数会给出相同的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM