<pre><code>chromPlot(gaps = cel_gap, figCols = 2, annot1 = annot1, annot2 = annot3, annot3 = annot2,
          chrSide=c(1, 1, -1, 1, -1, 1, -1, 1))
</code></pre>

<p>The <code>chrSide</code> argument decides on which side the histogram goes, so it can be used to solve my problem. The bars are not stacked but the result is the same: more accurate visualisation. </p>

<p>Thanks to Llopis for the guidance.</p>

<p><a href="https://i.sstatic.net/VkMv9.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/VkMv9.png" alt="karyotype"></a></p>

CC BY-SA 4.0
2018-06-25T14:09:31.313Z
2018-06-25T14:09:31.313Z
Biomagician
<p>I have a data frame containing 4 columns:</p>

<ul>
<li>Chrom: chromosome name of the feature</li>
<li>Start: starting base of the feature </li>
<li>End: end base of the feature</li>
<li>Name: name of the feature, e.g. 5S ribosomal RNA</li>
</ul>

<p>The head of the data frame is shown below:</p>

<pre><code>      Chrom    Start      End                        Name
    1     1 15390242 15390720 16S ribosomal RNA (partial)
    2     1 15390900 15391794 16S ribosomal RNA (partial)
    3     1 15392798 15396046           23S ribosomal RNA
    4     1 15397439 15397917 16S ribosomal RNA (partial)
    5     1 15398097 15398991 16S ribosomal RNA (partial)
    6     1 15399995 15403243           23S ribosomal RNA
</code></pre>

<p>I want to plot these features on the karyotype of <em>C. elegans</em>. I am using the <a href="https://bioconductor.org/packages/devel/bioc/vignettes/chromPlot/inst/doc/chromPlot.pdf" rel="nofollow noreferrer">chromPlot</a> package from Bioconductor.</p>

<p>I am using the following code:</p>

<ul>
<li><p>Subsetting the original data frame to get a data frame for each feature type: 5S, 16S and 23S rRNAs</p>

<pre><code>annot1 &lt;- dplyr::filter(cel, Name == '5S ribosomal RNA')
annot2 &lt;- dplyr::filter(cel, Name == '23S ribosomal RNA')
annot3 &lt;- dplyr::filter(cel, Name == '16S ribosomal RNA (partial)')
</code></pre>

<p>and then plot:</p>

<p>chromPlot(gaps = cel, figCols = 2, annot1 = annot1, annot2 = annot2)</p></li>
</ul>

<p><a href="https://i.sstatic.net/4HnwQ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4HnwQ.png" alt="Karyotype with 2 annotations"></a></p>

<p>This is OK because the two features are far away in the genome. However, if I try:</p>

<pre><code>chromPlot(gaps = cel_gap, figCols = 2, annot1 = annot1, annot2 = annot2,
          annot3 = annot3)
</code></pre>

<p><a href="https://i.sstatic.net/hWrx3.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/hWrx3.png" alt="Karyotype with 3 annotations"></a></p>

<p>one of the features masks the other because they are close to each other in the genome. How can I make the green bar stack on top of the yellow one instead of covering it?</p>

CC BY-SA 4.0
2018-06-25T08:56:48.153Z
Did you tried changing the order ? `annot1 = annot1, annot2 = annot3, annot3 = annot2)` If the annot_n are plotted in that order, simply changing the size will change the results as desired
llrs
CC BY-SA 4.0
2018-06-25T10:23:45.730Z
good idea, but then the green bar is half masked by the yellow bar and this gives the wrong impression of size.
Biomagician
CC BY-SA 4.0
2018-06-25T11:08:05.930Z
I'm not sure if this is possible at all with chromPlot. Are you sure there is the possibility to make this work as you wish? (have you seen it elsewhere?). Maybe this is a question for the developers themselves
llrs
CC BY-SA 4.0
2018-06-25T12:48:26.017Z
p. 28 of the manual seems to make it work: https://bioconductor.org/packages/devel/bioc/vignettes/chromPlot/inst/doc/chromPlot.pdf
Biomagician
CC BY-SA 4.0
2018-06-25T12:51:02.560Z
Then you might need to check what "chrSide" parameter does, because is the only difference I see. (And I am not sure that each bar is just added at the top of the other bar, but that could be the effect of `chrSide`)
llrs
CC BY-SA 4.0
2018-06-25T14:06:48.857Z
chrSide decides on which side this histogram is. I now put 2 and 2 together and solved my problem, thanks.
Biomagician
<r><bioconductor><visualization><chromplot>
How to superimpose barplots in karyotype graphic using the chromPlot Bioconductor package?
# How to superimpose barplots in karyotype graphic using the chromPlot Bioconductor package?

(Asked by: username_0 on 2018-06-24)

I have a data frame containing 4 columns:

Chrom: chromosome name of the feature
Start: starting base of the feature 
End: end base of the feature
Name: name of the feature, e.g. 5S ribosomal RNA

The head of the data frame is shown below:
      Chrom    Start      End                        Name
    1     1 15390242 15390720 16S ribosomal RNA (partial)
    2     1 15390900 15391794 16S ribosomal RNA (partial)
    3     1 15392798 15396046           23S ribosomal RNA
    4     1 15397439 15397917 16S ribosomal RNA (partial)
    5     1 15398097 15398991 16S ribosomal RNA (partial)
    6     1 15399995 15403243           23S ribosomal RNA

I want to plot these features on the karyotype of C. elegans. I am using the chromPlot package from Bioconductor.
I am using the following code:

Subsetting the original data frame to get a data frame for each feature type: 5S, 16S and 23S rRNAs
annot1 <- dplyr::filter(cel, Name == '5S ribosomal RNA')
annot2 <- dplyr::filter(cel, Name == '23S ribosomal RNA')
annot3 <- dplyr::filter(cel, Name == '16S ribosomal RNA (partial)')

and then plot:
chromPlot(gaps = cel, figCols = 2, annot1 = annot1, annot2 = annot2)


This is OK because the two features are far away in the genome. However, if I try:
chromPlot(gaps = cel_gap, figCols = 2, annot1 = annot1, annot2 = annot2,
          annot3 = annot3)


one of the features masks the other because they are close to each other in the genome. How can I make the green bar stack on top of the yellow one instead of covering it?

**Tags:** r, bioconductor, visualization, chromplot
> **Comments:**
> **username_1**: Did you tried changing the order ? `annot1 = annot1, annot2 = annot3, annot3 = annot2)` If the annot_n are plotted in that order, simply changing the size will change the results as desired  
> **username_0**: good idea, but then the green bar is half masked by the yellow bar and this gives the wrong impression of size.  
> **username_1**: I'm not sure if this is possible at all with chromPlot. Are you sure there is the possibility to make this work as you wish? (have you seen it elsewhere?). Maybe this is a question for the developers themselves  
> **username_0**: p. 28 of the manual seems to make it work: https://bioconductor.org/packages/devel/bioc/vignettes/chromPlot/inst/doc/chromPlot.pdf  
> **username_1**: Then you might need to check what "chrSide" parameter does, because is the only difference I see. (And I am not sure that each bar is just added at the top of the other bar, but that could be the effect of `chrSide`)  
> **username_0**: chrSide decides on which side this histogram is. I now put 2 and 2 together and solved my problem, thanks.  

---

## 1 answers

### Answer by username_0 on 2018-06-25. Score: 2 | Accepted answer

chromPlot(gaps = cel_gap, figCols = 2, annot1 = annot1, annot2 = annot3, annot3 = annot2,
          chrSide=c(1, 1, -1, 1, -1, 1, -1, 1))

The chrSide argument decides on which side the histogram goes, so it can be used to solve my problem. The bars are not stacked but the result is the same: more accurate visualisation. 
Thanks to Llopis for the guidance.


---

