'ggplot2 : Can't add ` ` to a ggplot object
everyone I generated 2 ggplot figures and I would like now to add them into the same figure, to do that I simply add the +
. So I have 2 plots : (1 ggtree and 1 heatmap)
and I'm trying to add them in the same plot with :
ggplot<- gg_tr + gg_heat + plot_annotation(tag_levels="A")
But then I get the following issue message:
Error : Can't add `gg_heat` to a ggplot object.
Run `rlang::last_error()` to see where the error occurred.
Solution 1:[1]
library(patchwork)
gg_tr + gg_heat
Solution 2:[2]
If using ggpubr::ggarrange()
, you need to put a comma and not a +
.
ggarrange(histo_qmean, histo_gmean, histo_qmed, histo_gmed,
labels = c("A", "B", "C", "D"),
ncol = 2, nrow = 2)
I got the same error by wrongly using +
, for anyone looking for it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Duck |
Solution 2 | Minh-Anh Huynh |