Error in ggtree relating to tippoint size (geom_tippoint): object 'node' not found

168 Views Asked by At

I'm currently trying to make the size of the tips of my tree correspond to a given size that is stored in a column in a data frame. The value is called PSV and PSV is between 0 and 1.

When I try to follow previous examples of code, I encounter an error (see below), however when I have tried other things to see what might work, I have managed to get it to work. However, this isn't the best way and I don't understand what is going wrong.

Here is the code I have been working with:

Base tree to work with

p1 <- ggtree(aleiodes_tree_rooted, branch.length = "none") + geom_tiplab(size = 3, offset = 1)

Add matrix (habitat variables)

p2 <- gheatmap(p1, phylo_traits_selected, low = "thistle", high = "maroon", colnames_position = "top", font.size = 2, offset = 4)

Up until now, everything has been fine. The next section is where I meet an issue

Add tippoints as associated with PSV size

The first line of code works. phylo_traits_PSV is a data frame with a column called PSV, where every value is between 0 and 1. In order to make the tips look good, I added +0.01*7. However, I am very much aware that this isn't the way that tippoint size is usually set, and should look something more like the code before. I have added the error that I get underneath.

This works

p3 <- p2 + geom_tippoint(size = ((phylo_traits_PSV$PSV)+0.01)*7)

This doesn't - but why?

p3 <- p2 + geom_tippoint(aes(size = PSV), data = phylo_traits_PSV) + scale_size_continuous(range = c(2, 6)) + theme_tree()

Error:

plot(p3)

Error in geom_point2(): ! Problem while computing aesthetics. ℹ Error occurred in the 6th layer. Caused by error: ! object 'node' not found

Thank you for your help!

0

There are 0 best solutions below