是否可以在 ggtree 中将 geom_insert() 用于圆形树?

Is it possible to use geom_insert() in ggtree for circular trees?

我试图将我的祖先状态估计结果作为系统发育树节点处的饼图包含在内。它适用于矩形树,但我真的更喜欢圆形树。但是,当我尝试这样做时,我收到一条错误消息:

Error: annotation_custom only works with Cartesian coordinates

可重现的例子:

library(phytools)
library(tidyverse)
library(ggtree)
data("anoletree")

x <- getStates(anoletree,"tips")
cols_x <- setNames(palette()[1:length(unique(x))],sort(unique(x)))
fitER <- ape::ace(x,anoletree,model="ER",type="discrete")
ancstats_x <- as.data.frame(fitER$lik.anc)
ancstats_x$node <- 1:anoletree$Nnode+Ntip(anoletree)
tree2 <- full_join(anoletree, data.frame(label = names(x), stat = x ), by = 'label')
p_x <- ggtree(tree2, layout = "circular") + geom_tiplab() +
  geom_tippoint(aes(color = stat)) + 
  scale_color_manual(values = cols_x) +
  theme(legend.position = "right") + 
  xlim(NA, 8)
pies_x <- nodepie(ancstats_x, cols = 1:6)
pies_x <- lapply(pies_x, function(g) g+scale_fill_manual(values = cols_x))
p_x2 <- p_x + geom_inset(pies_x, width = .1, height = .1) 

有没有可能避免这个错误? 任何帮助将不胜感激

这是因为 ggplot 的 annotation_custom 不适用于圆形图。您可以参考 https://github.com/YuLab-SMU/ggtree/issues/419 以获得准确的指南和 how-to!