<p>What you are looking for is <code>facetting</code>. Using this key word on any search engines you will find dozen of answers describing its use: <a href="https://ggplot2.tidyverse.org/reference/facet_grid.html" rel="nofollow noreferrer">https://ggplot2.tidyverse.org/reference/facet_grid.html</a> and <a href="https://ggplot2.tidyverse.org/reference/facet_wrap.html" rel="nofollow noreferrer">https://ggplot2.tidyverse.org/reference/facet_wrap.html</a></p>

<p>To prepare the faceting in <code>ggplot2</code>, a possible way is to bind both dataframes together by first specifying which group they belong such as:</p>

<pre class="lang-r prettyprint-override"><code>cytokine<span class="math-container">$Group = "Cytokine"
il17$</span>Group = "IL17"
DF &lt;- 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
</code></pre>

<p>Then, use <code>facet_grid</code> function of <code>ggplot2</code>:</p>

<pre class="lang-r prettyprint-override"><code>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")
</code></pre>

<p><a href="https://i.sstatic.net/P9c3f.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/P9c3f.png" alt="enter image description here"></a></p>

<p>Alternatively, you can use <code>facet_grid</code> (or <code>facet_wrap</code>) to have your plot in a single row:</p>

<pre class="lang-r prettyprint-override"><code>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")
</code></pre>

<p><a href="https://i.sstatic.net/AohiU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/AohiU.png" alt="enter image description here"></a></p>

<p><strong>Reproducible data example</strong></p>

<pre class="lang-r prettyprint-override"><code>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 = &lt;pointer: 0x55bfc0db9350&gt;)
</code></pre>

<p>and</p>

<pre class="lang-r prettyprint-override"><code>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 = &lt;pointer: 0x55bfc0db9350&gt;)
</code></pre>

CC BY-SA 4.0
2020-02-11T10:36:12.730Z
Sorry how I can place responders and non responders for each group next to each other? I mean for example for OBP responders and non responders being placed next to each other
Zizogolu
CC BY-SA 4.0
2020-02-10T22:20:47.523Z
2020-02-10T22:28:07.117Z
2020-02-10T22:28:07.117Z
dc37
<p>I have this data frame</p>

<blockquote>
  <p>head(d)</p>
</blockquote>

<pre><code># A tibble: 6 x 3
  gene  variable       value
1 CCT5  Res_immune     10.6 
2 CCT5  Non_res_immune 10.5 
3 CDK1  Res_immune      9.25
4 CXCL5 Non_res_immune  9.82
5 GBP1  Res_immune      9.04
6 GBP1  Non_res_immune  9.43
&gt; 
</code></pre>

<p>And this code</p>

<pre><code>library(ggplot2)
library(ggrepel)
ggplot(d, 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)
</code></pre>

<p>The genes in first column are involved in cytokine signaling pathway in two groups of patients</p>

<p>This is my plot
<a href="https://i.sstatic.net/2ciYI.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2ciYI.png" alt="enter image description here"></a></p>

<p>I have another data frame for genes in IL17 signaling in the sample patients like</p>

<p>head(d)</p>

<pre><code># A tibble: 6 x 3
  gene  variable       value
  &lt;chr&gt; &lt;chr&gt;          &lt;dbl&gt;
1 CDK6  Res_immune     17.6 
2 IL6  Non_res_immune 14.5 
3 CXCL8  Res_immune      1.25
</code></pre>

<p>How I can put plots from both data in a grade like below where the name of pathways shown instead of DEL, INS, SNP and total like below picture?</p>

<p><img src="https://i.sstatic.net/aRH0K.png" alt=""></p>

CC BY-SA 4.0
2020-02-10T22:05:26.773Z
you should add a reproducible example of both dataframe (Cytokine and IL-17 signaling) by providing the output of `dput(head(d))`. It will make things easier for people trying to help you.
dc37
<r><ggplot2>
Griding ggplot object in r
# Griding ggplot object in r

(Asked by: username_0 on 2020-02-10)

I have this data frame

head(d)

# A tibble: 6 x 3
  gene  variable       value
1 CCT5  Res_immune     10.6 
2 CCT5  Non_res_immune 10.5 
3 CDK1  Res_immune      9.25
4 CXCL5 Non_res_immune  9.82
5 GBP1  Res_immune      9.04
6 GBP1  Non_res_immune  9.43
> 

And this code
library(ggplot2)
library(ggrepel)
ggplot(d, 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)

The genes in first column are involved in cytokine signaling pathway in two groups of patients
This is my plot

I have another data frame for genes in IL17 signaling in the sample patients like
head(d)
# A tibble: 6 x 3
  gene  variable       value
             
1 CDK6  Res_immune     17.6 
2 IL6  Non_res_immune 14.5 
3 CXCL8  Res_immune      1.25

How I can put plots from both data in a grade like below where the name of pathways shown instead of DEL, INS, SNP and total like below picture?

**Tags:** r, ggplot2
> **Comments:**
> **username_1**: you should add a reproducible example of both dataframe (Cytokine and IL-17 signaling) by providing the output of `dput(head(d))`. It will make things easier for people trying to help you.  

---

## 1 answers

### Answer by username_1 on 2020-02-10. Score: 4 | Accepted answer

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 = )

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 = )

> **Comments:**
> **username_0**: Sorry how I can place responders and non responders for each group next to each other? I mean for example for OBP responders and non responders being placed next to each other  

---

