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.
Elements that are normally added to a ggplot with operator + , such as scales, themes, aesthetics can be replaced with the %+% operator. The situation with layers is different as a plot may contain multiple layers and layers are nameless. With layers %+% is not a replacement operator.
%>% is a pipe operator reexported from the magrittr package. Start by reading the vignette. Adding things to a ggplot changes the object that gets created. The print method of ggplot draws an appropriate plot depending upon the contents of the variable.
ggplot only works with data frames, so we need to convert this matrix into data frame form, with one measurement in each row. We can convert to this “long” form with the melt function in the library reshape2 .
library(patchwork)
gg_tr + gg_heat
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With