1

I managed to plot a phylogenetic tree using ggtree and pdf() but cant break it down to fit on multiple pages to make it readable for users.

You can make a tree following this link

Heres the code for the tree and its output :

make_tree_plot <- function(phy_tree, tip_label){
   p <- ggtree(phy_tree) + geom_nodepoint(color='purple', size=2, alpha=0.2) + geom_tippoint() 

  ...# a lot of code to create facet_plots to have all the variables included in the panel. We end up with           the final form p11 :

  assign(p11, facet_plot(z11), panel=colnames(info_df[i]), geom=geom_text,
                  aes(x=0, label=unlist(info_df[11])), data=info_df))

  gt <- ggplot_gtable(ggplot_build(p11))
  grid.draw(gt)
}
# Master
pdf("plots2.pdf", width=35, height=45, paper='a4r')
make_tree_plot(tree, tips_info)
dev.off()

We get this CONDENSED tree in one-page pdf.

We get this CONDENSED tree in one page pdf

This is the expected output.

This is the expected output

Considering the nature of the plot, I can't simply divide the dataset and create multiple trees. Only one tree can be created and then divided in multiple pages.

I am coding in VS code and have tried .rmd files for printing but it wasn't the ideal for me. I managed to print matrixes over multiple pages with pdf(), but for this phylo tree im honestly facing a wall.

  • I created my own `ggtree` object and used `pdf` with your args to save it. It was as big as dictated by the arguments. By default, I use Mac's Preview for pdf rendering. I also tried Adobe: still the right size. I have Adobe Pro; it could be different with pdf reader. ...It looks like you're new to SO; welcome to the community! If you want great answers quickly, make your question reproducible, including sample data like the output from `dput()` or `reprex::reprex()`, the libraries used, etc. Check it out: [making R reproducible questions](https://stackoverflow.com/q/5963269). – Kat Jun 27 '23 at 01:21
  • Thanks for the kind welcome! I found the following [post](http://blog.phytools.org/2015/03/splitting-tree-over-mutiple-plotting.html) which shows how to print the phylo tree over multiple pages pdf, but this doesnt work with a gtable\gtree object (phylo tree mixed with columns of information)! I've tried ggforce and marrangegrob without success yet. – SixtyCorrupted Jun 29 '23 at 15:05
  • Heres what i tried for [marrangegrob](https://cran.r-project.org/web/packages/gridExtra/vignettes/arrangeGrob.html#multiple-pages-output) and for [ggforce](https://stackoverflow.com/questions/48544039/how-to-save-output-from-ggforcefacet-grid-paginate-in-only-one-pdf) – SixtyCorrupted Jun 29 '23 at 15:15

1 Answers1

0

Found out how to plot it!! The key was to use plot.margin with a rolling window.

for (j in 0:30){
    grid.newpage()
    pt <- p11 + theme(plot.margin = unit(c(0-19*j,0,-400+19*j,0), "cm")) # c(top,right,bottom,left)
    gt <- ggplot_gtable(ggplot_build(pt))
    grid.draw(gt)
}

enter image description here

enter image description here