I am trying to plot thin slices at the bottom of my phylogeny to visualize the distribution of a particular trait. Similar to this plot:
But I can't figure out how to do it in either ape or ggtree frameworks.
Here is some code that shows how far I have got:
library(ggtree)
library(tidytree)
library(ape)
n = 100
x = rcoal(n)
d = data.frame(label = x$tip.label,
trait = sample(x = 0:1, size = n, replace = TRUE))
## ggtree
x_join = full_join(as_tibble(x), d, by = "label")
tree_df = as.treedata(x_join)
ggtree(tree_df) +
geom_tippoint(aes(colour = factor(trait)))
## ape: Only plotting squares
plot(x)
tiplabels(pch = 15, col = ifelse(d$y == 1, "black", "red"))