<p>Using Google well is one of the best skillsets you can possibly learn in programming-allied fields. The style of plot you're looking for is a &quot;grouped bar plot&quot;. I googled &quot;r grouped bar plot&quot; and found a nice link: <a href="https://www.r-graph-gallery.com/48-grouped-barplot-with-ggplot2.html" rel="nofollow noreferrer">https://www.r-graph-gallery.com/48-grouped-barplot-with-ggplot2.html</a></p>
<p>The key is to use <code>position=dodge</code> alongside <code>color=Condition, x=&quot;Read count&quot;, y=miRNA</code> )not sure ow you'd quote the name <code>&quot;Read count&quot;</code>, might be better off renaming that column to <code>readcount</code>).</p>

CC BY-SA 4.0
2022-03-09T17:37:18.703Z
2022-03-17T21:36:00.867Z
2022-03-17T21:36:00.867Z
Ram RS
<p>I have raw read counts of miRNAs in two conditions like below</p>
<pre><code>&gt; head(long1)
             miRNA Read count Condition
1:  hsa-miR-539-3p         33    living
2: hsa-miR-199b-5p        102    living
3: hsa-miR-146a-3p         27    living
4:   hsa-let-7a-3p        186    living
5:    hsa-miR-1275         54    living
6:  hsa-miR-29a-3p       6464    living
&gt; 
</code></pre>
<p>For each individual miRNAs, I want to show the difference of raw read counts across conditions by</p>
<pre><code>p=ggplot(data = long1, aes(x=long1<span class="math-container">$miRNA, y=long1$</span>`Read count`)) + geom_boxplot(aes(fill=Condition))
p &lt;- p + guides(fill=guide_legend(title=&quot;Condition&quot;))
p &lt;- p + xlab(&quot;miRNAs&quot;) + ylab(&quot;Raw mapped reads&quot;) + ggtitle(&quot;s vs living with cancer&quot;)
p + facet_wrap( ~ miRNA, scales=&quot;free&quot;)+theme_bw() add_pval(p, pairs = list(c(&quot;s&quot;, &quot;living&quot;)), test='wilcox.test')
</code></pre>
<p>Which returns this</p>
<p>[![enter image description here][1]][1]</p>
<p>This plot is not good</p>
<p>How I can a plot like below in which miRNAs are on Y axis and two colours shows the conditions like this</p>
<p><a href="https://i.sstatic.net/0iSov.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/0iSov.jpg" alt="enter image description here" /></a></p>

<r><rna-seq><ggplot2>
A two color bar plot in R
# A two color bar plot in R

(Asked by: username_0 on 2022-03-09)

I have raw read counts of miRNAs in two conditions like below
> head(long1)
             miRNA Read count Condition
1:  hsa-miR-539-3p         33    living
2: hsa-miR-199b-5p        102    living
3: hsa-miR-146a-3p         27    living
4:   hsa-let-7a-3p        186    living
5:    hsa-miR-1275         54    living
6:  hsa-miR-29a-3p       6464    living
> 

For each individual miRNAs, I want to show the difference of raw read counts across conditions by
p=ggplot(data = long1, aes(x=long1$miRNA, y=long1$`Read count`)) + geom_boxplot(aes(fill=Condition))
p <- p + guides(fill=guide_legend(title="Condition"))
p <- p + xlab("miRNAs") + ylab("Raw mapped reads") + ggtitle("s vs living with cancer")
p + facet_wrap( ~ miRNA, scales="free")+theme_bw() add_pval(p, pairs = list(c("s", "living")), test='wilcox.test')

Which returns this
[![enter image description here][1]][1]
This plot is not good
How I can a plot like below in which miRNAs are on Y axis and two colours shows the conditions like this

**Tags:** r, rna-seq, ggplot2

---

## 1 answers

### Answer by username_1 on 2022-03-09. Score: 4

Using Google well is one of the best skillsets you can possibly learn in programming-allied fields. The style of plot you're looking for is a "grouped bar plot". I googled "r grouped bar plot" and found a nice link: <https://www.r-graph-gallery.com/48-grouped-barplot-with-ggplot2.html>

The key is to use `position=dodge` alongside `color=Condition, x="Read count", y=miRNA` )not sure ow you'd quote the name `"Read count"`, might be better off renaming that column to `readcount`).


---

