Combine phylogenetic tree with x, y graph

I am trying to organize a phylogenetic tree on a graph showing physiological data for a set of related organisms. Something like the picture below. It was combined into a powerpoint from two separate schedules. I assume that he is doing this work, but I was hoping to create a single image, which, I think, will be easier to format in the document. I can create the graph that I want to use ggplot2 and import the tree with the monkey. I thought that there should be a way to save the tree as a graphical object and then organize it using a graph using the gridarrange function in gridExtra. The problem is that the monkey will not allow me to save the tree as a graphic object, for example,

p2<-plot(tree, dir = "u", show.tip.label = FALSE) 

just draws a tree, and when you call p2, it just gives a list of arguments. I am wondering if anyone has any tips.

Thanks!

enter image description here

+4
source share
2 answers

I'm not sure if this will work with gtable from CRAN

 require(ggplot2) require(gridBase) require(gtable) p <- qplot(1,1) g <- ggplotGrob(p) g <- gtable_add_rows(g, unit(2,"in"), nrow(g)) g <- gtable_add_grob(g, rectGrob(), t = 7, l=4, b=7, r=4) grid.newpage() grid.draw(g) #grid.force() #grid.ls(grobs=F, viewports=T) seekViewport("layout.7-4-7-4") par(plt=gridPLT(), new=TRUE) plot(rtree(10), "c", FALSE, direction = "u") upViewport() 

enter image description here

+3
source

I would first like to thank baptiste for ALL of his many answers, which solved most of my problems with ggplot2.

Secondly, I had a similar question, which was supposed to include a tree from a monkey inside the heat map obtained with ggplot2. The Baptist made my day, and although my simplified version could help. I used only what was useful to me (removing gg_rows add).

 library(ape) tr <- read.tree("mytree.tree") # heat is the heatmap ggplot, using geom_tile g <- ggplotGrob(heat) grid.newpage() grid.draw(g) # use oma to reduce the tree so it fits par(new = TRUE, oma = c(5, 4, 5, 38)) plot(tr) nodelabels(tr$node.label, cex = 1, frame = "none", col = "black", adj = c(-0.3, 0.5)) add.scale.bar() # use dev.copy2pdf and not ggsave dev.copy2pdf(file = "heatmap_prob.pdf") 

result here heatmaptree

+1
source

Source: https://habr.com/ru/post/1492821/


All Articles