Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with geom_inset of nodepies onto circular/radial/fan trees #599

Open
ruthvikpsi opened this issue Jan 25, 2024 · 0 comments
Open

Error with geom_inset of nodepies onto circular/radial/fan trees #599

ruthvikpsi opened this issue Jan 25, 2024 · 0 comments

Comments

@ruthvikpsi
Copy link

Hi ggtree team,

I have been trying to plot discrete ancestral states at nodes with pie charts created using nodepie(). It works completely fine with the default layout. However, my original tree is large (>3000 tips) and I would like to represent the tree in a circular/fan layout with pie charts on the nodes. But, I get this error with the layouts "circular", "fan" and "radial":

Error in annotation_custom():
! Problem while converting geom to grob.
ℹ Error occurred in the 6th layer.
Caused by error in draw_panel():
! annotation_custom() only works with coord_cartesian()

Here's a reproducible example from the example dataset anoletree data:

library(ggtree)
library(dplyr)
library(phytools)

data(anoletree)
x <- getStates(anoletree,"tips")
tree <- as.phylo(anoletree)

cols <- setNames(palette()[1:length(unique(x))],sort(unique(x)))
fitER <- ape::ace(x,tree,model="ER",type="discrete")
ancstats <- as.data.frame(fitER$lik.anc)
ancstats$node <- 1:tree$Nnode+Ntip(tree)

tree2 <- full_join(tree, data.frame(label = names(x), stat = x ), by = 'label')
p <- ggtree(tree2, layout = "circular") + geom_tiplab() +
  geom_tippoint(aes(color = stat)) + 
  scale_color_manual(values = cols) +
  theme(legend.position = "right") + 
  xlim(NA, 8)

pies <- nodepie(ancstats, cols = 1:6)
pies <- lapply(pies, function(g) g+scale_fill_manual(values = cols))
p2 <- p + geom_inset(pies, width = .1, height = .1) 
p2

Session Info:

R version 4.3.2 (2023-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.utf8 LC_CTYPE=English_United Kingdom.utf8
[3] LC_MONETARY=English_United Kingdom.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.utf8

time zone: Europe/London
tzcode source: internal

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] phytools_2.1-1 maps_3.4.2 ape_5.7-1 dplyr_1.1.4 ggtree_3.10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant