How can I combine a ggtree and a histogram?

202 Views Asked by At

I want to combine the ggtree generated p and the histogram based on dat. Both the phylogenetic tree and histogram have same entries, but the only thing I observe is the phylogenetic tree without any text or histogram. I don't understand why the tree and the histogram don't combine.

library(ggtree)
library(ggplot2)


tree <- read.tree("mammal2.nh")

#My newick file "mammal2.nh" is : 
#(((((((((((((((((((((((((Monodelphis domestica)Monodelphis)Didelphinae)Didelphidae)Didelphimorphia)Metatheria,(((((((((((Mus musculus)Mus)Mus)Murinae)Muridae)Muroidea)Myomorpha,(((((Marmota marmota)Marmota)Marmotini)Xerinae)Sciuridae)Sciuromorpha)Rodentia)Glires)Euarchontoglires)Boreoeutheria)Eutheria)Theria)Mammalia)Amniota,((((((((Xenopus laevis)Xenopus)Xenopus)Xenopodinae)Pipidae)Pipoidea)Anura)Batrachia)Amphibia)Tetrapoda)Dipnotetrapodomorpha)Sarcopterygii)Euteleostomi)Teleostomi)Gnathostomata)Vertebrata)Craniata)Chordata)Deuterostomia)Bilateria)Eumetazoa)Metazoa)Opisthokonta)Eukaryota)cellular_organisms);


p<- ggtree(tree, branch.length='none')



Name = list('Marmota Marmota', 'Monodelphis domestica', 'Mus musculus', 'Xenopus laevis')
pcnt = list(5,20,6,9)

dat <- do.call(rbind, Map(data.frame, Name=Name, pcnt=pcnt))


p2 <- geom_facet(p,panel  = 'aa',
  data=dat,
  geom=ggstance::geom_histogramh(),
  aes(x=pcnt, y=Name),
  stat="identity"
)

p2

This is how I wanted it to look like in the end. Panels "tree" and "trait".

http://yulab-smu.top/treedata-book/chapter7

0

There are 0 best solutions below