I have two plots that I want to place next to each other on a grid. If they were both ggplot2 plots I'd just do something like this:
plot_grid(plot_a,plot_b,ncol=2)
using the cowplot package.
However, one of my plots I have created using the ComplexHeatmap package. While the other is created with ggplot2. That is:
> class(plot_a)
[1] "gg" "ggplot"
> class(plot_b)
[1] "Heatmap"
attr(,"package")
[1] "ComplexHeatmap"
How can I combine these plots in a grid and more generally what is the recommended way of making a grid of plots of different types?
Thanks.
This was exactly what I was looking for. Thank you!
Thank you for this great package!
In line with this answer I am wondering if there is any way to extract the annotation(s) as a separate grob, for increased flexibility in combination with the plot_grid function in the cowplot package, similar the solution for extracting legend (se below)?
The legend can be extracted by:
With regards,
The heatmap annotations are drawn by
draw,HeatmapAnnotation-method
. You can check the documentation at https://jokergoo.github.io/ComplexHeatmap/reference/draw-HeatmapAnnotation-method.htmlTo draw the animations, you need to first create a viewport to put them:
Thank you for your quick reply!
I am still struggeling to get the annotation-bar identical to the one in the heatmap-object. Either I can use draw on the 'HeatmapAnnotation' object directly, but then the ordering and the position and the width are not the same as the heatmap main body, or I can try to extract the annotation from the annotation-slot in the heatmap-list as you have shown, but still I am facing difficulties getting the size, position, gap, column split, ordering of columns correct. Ideally I would like to extract all this as it is in the heatmap-list object, and draw the grob separately in the plot_grid function.
With regards,
Then I would suggest using
HeatmapAnnotation(...) %v% NULL
, but still you need to manually set the order. You can try the following code, but I am not sure they 100% work:This is getting close, thanks again! I am still not able to make the topannotation have columnsplit as the heatmap body do, and am also struggling to make the top_annotation grob have the same x-position and width as the heatmap body.
To get the column_order I used
Then can you try to put the top annotation with a zero-row matrix?
This is even closer, the gap and the splitting and order are right. Still I do not have the proper width and x-position for the annotation bar, to make it inheret the space above the heatmap main body, for alignment, as the heatmap also has dendrograms and row labels.
Here is my code, although not working without input variables split_cell etc.:
It is not a ggplot2 plot, so it won't automatically align to other figures, you should manually adjust the plot size by the
padding
argument, e.g.draw(ht_a, padding = unit(c(1, 1, 1, 1), "mm"))
. The four values are the space on the bottom, left, top and right of the heatmap.Thank you again for very good help!