I have a COMPASS heatmap I would like to display in a figure with some other plots, like the figure shown here from this paper:
I am curious how the figure was created. This is the closest I can get using cowplot and some example data:
library(COMPASS) # modified
library(cowplot)
library(ggplot2)
library(gtable)
# Prepare heatmap
cytokine_annotation_colors <- c("black", "black", "black", "black", "black", "black", "black")
grouping <- "Status"
compassResult <- readRDS("/path/to/compassResult.rds")
# Modified plot.COMPASSResult to return heatmap as grob
heatmap_grob <- plot_1.COMPASSResult(compassResult, grouping, show_rownames = FALSE,
main = "Heatmap of Mean Probability of Response",
fontsize=14, fontsize_row=13, fontsize_col=11,
cytokine_annotation_colors=cytokine_annotation_colors)
class(heatmap_grob) # [1] "gTree" "grob" "gDesc"
# Turn grob into gtable to make compatible with cowplot
heatmap_gtable <- gtable(unit(1, c("grobwidth"), data=heatmap_grob), unit(1, "grobheight", data=heatmap_grob))
heatmap_gtable <- gtable_add_grob(heatmap_gtable, heatmap_grob, 1, 1)
example_plot <- ggplot(data=mtcars, aes(x=mpg, y=cyl)) + geom_point() + labs(title="mtcars example plot")
cowplot_figure <- plot_grid(heatmap_gtable, NULL, example_plot, rel_widths = c(2, 4, 2), labels = c("A", "", "B"), nrow=1)
ggsave(filename="cowplot_fig_example.png",
plot=cowplot_figure, path="/home/malisa/Desktop", device="png",
width=9, height=6, units="in")
Is there an easy solution using R? If not, I could perhaps save the heatmap as an svg and then put together a figure using some other software...?