在 R 中获取"tree badly conformed; cannot plot. Check the edge matrix"错误



我正在尝试使用R绘制系统发育树,但我得到了边缘矩阵错误的检查。我该如何解决这个问题?我试图更改seq值以避免出现NA。这棵树可以用ott数字画得很好,但我想要一些足够体面的东西来出版。如果有任何帮助,我将不胜感激。

library(rncl)
library(rotl)
taxa<-c("Gastrotricha","Platyhelminthes", "Ectoprocta","Brachiopoda","Nemertea", "Mollusca","Annelida","Entoprocta",
"Cycliophora","Mesozoa","Rotifera", "Gnathostenetroididae","Micrognathozoa", "Chaetognatha","Kinorhyncha",
"Priapulida","Loricifera","Nematoda", "Nematomorpha","Tardigrada", "Onychophora","Arthropoda","Vertebrata", 
"rochordata","Cephalochordata", "Hemichordata","Echinodermata", "Xenacoelomorpha", "Cnidaria", "Ctenophora",
"Placozoa","Porifera")

resolved_names <- tnrs_match_names(taxa)
phyl_tree <- tol_induced_subtree(ott_ids=ott_id(resolved_names)[is_in_tree(ott_id(resolved_names))])
plot(phyl_tree, cex = .8, label.offset = .1, no.margin = TRUE)
name = phyl_tree$tip.label
name[1]=substr(name[1],0,10)
name[2]=substr(name[2],0,10)
name 
new_name=unlist(strsplit(name, split = "_"))[seq(1,54,by=2)]
phyl_tree$tip.label=new_name
plot(phyl_tree, cex = .8, label.offset = .1, no.margin = TRUE)

错误来自new_name的长度与树中的提示数不相同:

length(new_name) == Ntip(phyl_tree)

如果您想在没有_ott...位的情况下更新名称,可以使用以下代码:

## Splitting the characters after "_" and keeping only the first element
new_names <- unlist(lapply(strsplit(name, split = "_"), `[[`, 1))
## Replacing the new names
phyl_tree$tip.label <- new_names
## Plotting the updated labels
plot(phyl_tree, cex = .8, label.offset = .1, no.margin = TRUE)

最新更新