What you are looking for is facetting
. Using this key word on any search engines you will find dozen of answers describing its use: https://ggplot2.tidyverse.org/reference/facet_grid.html and https://ggplot2.tidyverse.org/reference/facet_wrap.html
To prepare the faceting in ggplot2
, a possible way is to bind both dataframes together by first specifying which group they belong such as:
cytokine$Group = "Cytokine"
il17$Group = "IL17"
DF <- rbind(cytokine,il17)
DF
gene variable value Group
1: CCT5 Res_immune 10.60 Cytokine
2: CCT5 Non_res_immune 10.50 Cytokine
3: CDK1 Res_immune 9.25 Cytokine
4: CXCL5 Non_res_immune 9.82 Cytokine
5: GBP1 Res_immune 9.04 Cytokine
6: GBP1 Non_res_immune 9.43 Cytokine
7: CDK6 Res_immune 17.60 IL17
8: IL6 Non_res_immune 14.50 IL17
9: CXCL8 Res_immune 1.25 IL17
Then, use facet_grid
function of ggplot2
:
library(ggplot2)
library(ggrepel)
ggplot(DF, aes(x = variable, y = value, fill = variable, label = gene))+
geom_boxplot(alpha = 0.2)+
geom_point(position = position_jitter(width = 0.2, seed = 2), show.legend = FALSE)+
geom_text_repel(position = position_jitter(0.2, seed = 2), show.legend = FALSE)+
facet_grid(Group~., scales = "free")

Alternatively, you can use facet_grid
(or facet_wrap
) to have your plot in a single row:
library(ggplot2)
library(ggrepel)
ggplot(DF, aes(x = variable, y = value, fill = variable, label = gene))+
geom_boxplot(alpha = 0.2)+
geom_point(position = position_jitter(width = 0.2, seed = 2), show.legend = FALSE)+
geom_text_repel(position = position_jitter(0.2, seed = 2), show.legend = FALSE)+
facet_wrap(.~Group, scales = "free")

Reproducible data example
structure(list(gene = c("CCT5", "CCT5", "CDK1", "CXCL5", "GBP1",
"GBP1"), variable = c("Res_immune", "Non_res_immune", "Res_immune",
"Non_res_immune", "Res_immune", "Non_res_immune"), value = c(10.6,
10.5, 9.25, 9.82, 9.04, 9.43), Group = c("Cytokine", "Cytokine",
"Cytokine", "Cytokine", "Cytokine", "Cytokine")), row.names = c(NA,
-6L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x55bfc0db9350>)
and
structure(list(gene = c("CDK6", "IL6", "CXCL8"), variable = c("Res_immune",
"Non_res_immune", "Res_immune"), value = c(17.6, 14.5, 1.25),
Group = c("IL17", "IL17", "IL17")), row.names = c(NA, -3L
), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x55bfc0db9350>)
dput(head(d))
. It will make things easier for people trying to help you. $\endgroup$