Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
like image 747
chippycentra Avatar asked Jun 26 '20 17:06

chippycentra


People also ask

What operator allows you to keep adding layers to a Ggplot () object?

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.

What does %>% do in Ggplot?

%>% 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.

Does Ggplot only work with data frames?

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 .


1 Answers

library(patchwork)
gg_tr + gg_heat
like image 144
Duck Avatar answered Nov 04 '22 01:11

Duck