Skip to content

Problem with nodepie when plotting ancestral reconstruction states as pies on trees #688

@Chloisf

Description

@Chloisf

Hi,

Thank you for this package which seems really useful for my research!

I am encountering this error which I am not sure how to fix. I have been following the guide 8.3.1 and 8.3.2 on this page
I have been trying to run the example with minor changes (trying to control the color):

library(ggtree)
library(phytools)

data(anoletree)
x <- getStates(anoletree,"tips")
tree <- 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)

########### plotting bars
bars <- nodebar(ancstats, cols=1:6, color=c("blue", "pink", "grey", "yellow", "purple","black"))
tree=as.phylo(tree)
tree2 <- full_join(tree, data.frame(label = names(x), stat = x ), by = 'label')
p <- ggtree(tree2) + geom_tiplab() +
  geom_tippoint(aes(color = stat)) + 
  scale_color_manual(values = c("blue", "pink", "grey", "yellow", "purple","black")) +
  theme(legend.position = "right") + 
  xlim(NA, 8)

p1 <- p + geom_inset(bars, width = .01, height = .01) 


###########plotting pies
pies <- nodepie(ancstats, cols = 1:6,  color=c("blue", "pink", "grey", "yellow", "purple","black"))

p2 = ggtree(tree2) + geom_tiplab() +
  geom_tippoint(aes(color = stat)) + 
  scale_color_manual(values = c("blue", "pink", "grey", "yellow", "purple","black")) +
  theme(legend.position = "right") + 
  xlim(NA, 8)

p2 <- p + geom_inset(pies, width = .1, height = .1) 

The guide example first shows how to put bars on nodes of the tree, then how to put pies.
I have no problem getting the expected result with bars, but somehow with pies I run into this error:

"Don't know how to automatically pick scale for object of type . Defaulting to continuous.
Error in geom_bar():
! Problem while computing aesthetics.
i Error occurred in the 1st layer.
Caused by error:
! Aesthetics are not valid data columns.
x The following aesthetics are invalid:

  • y = y
  • fill = fill
    i Did you mistype the name of a data column or forget to add after_stat()?"

I can run my plot p2 without problem until I add "geom_inset(pies, width = .1, height = .1) "
When I looked into "pies" and click on the first pie, I get the same error, so I am suspecting the problem comes in the first place from "pies <- nodepie(ancstats, cols = 1:6, color=c("blue", "pink", "grey", "yellow", "purple","black"))"

I am at a loss trying to adress y=y and fill=fill since these don't seem to be a part of the direct arguments of nodepie.

I would greatly appreciate some help to fix this or an alternate way to plot pies on the nodes of the ggtree!
Best,
Chloé

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions