<p>Did you try the <code>fill</code> argument?</p>

<p>Something like this:</p>

<pre><code>track &lt;- AnnotationTrack(start=c(1,5,7), end=c(2,6,10), strand=c('*','*','*'), stacking="dense", showFeatureId=TRUE, id=c('red','blue', 'red'), fill=c('red','blue', 'red'))
</code></pre>

CC BY-SA 3.0
2017-11-15T10:08:37.210Z
Thanks, seems to work, can't believe I missed that! What colours are accepted as arguments for `fill`?
Chris_Rands
CC BY-SA 3.0
2017-11-15T10:11:56.833Z
Probably all colors, [here](http://sape.inf.usi.ch/quick-reference/ggplot2/colour) a list of color names.
benn
CC BY-SA 3.0
2017-11-15T10:59:52.307Z
@Chris_Rands see `?plotTracks` for the options accepted by `plotTracks` which will then refer you to `?settings` for the various things you can tweak (long, long documentation). Finally, `availableDisplayPars(track)` will show you what you can set for `track`.
terdon
CC BY-SA 3.0
2017-11-15T10:02:28.663Z
2017-11-15T10:02:28.663Z
benn
<p>I'm learning the Gviz bioconductor package, I generate a plot as follows:</p>

<pre><code>library(Gviz)
track &lt;- AnnotationTrack(start=c(1,5,7), end=c(2,6,10), strand=c('*','*','*'), stacking="dense", showFeatureId=TRUE, id=c('red','blue', 'red'))
pdf(file=paste("test","pdf", sep="."))
plotTracks(track)
dev.off()
</code></pre>

<p><code>test.pdf</code> looks like this: <a href="https://i.sstatic.net/bXZPG.png" rel="noreferrer"><img src="https://i.sstatic.net/bXZPG.png" alt="enter image description here"></a></p>

<p>However, what I want is for the boxes to be coloured rather than labelled with the colour word, how to do this?</p>

<p>Note that my real example is much more complex than this.</p>

<r><bioconductor><gviz>
How can I colour boxes in Gviz AnnotationTrack in R?
# How can I colour boxes in Gviz AnnotationTrack in R?

(Asked by: username_0 on 2017-11-15)

I'm learning the Gviz bioconductor package, I generate a plot as follows:
library(Gviz)
track <- AnnotationTrack(start=c(1,5,7), end=c(2,6,10), strand=c('*','*','*'), stacking="dense", showFeatureId=TRUE, id=c('red','blue', 'red'))
pdf(file=paste("test","pdf", sep="."))
plotTracks(track)
dev.off()

test.pdf looks like this: 
However, what I want is for the boxes to be coloured rather than labelled with the colour word, how to do this?
Note that my real example is much more complex than this.

**Tags:** r, bioconductor, gviz

---

## 1 answers

### Answer by username_1 on 2017-11-15. Score: 8 | Accepted answer

Did you try the fill argument?
Something like this:
track <- AnnotationTrack(start=c(1,5,7), end=c(2,6,10), strand=c('*','*','*'), stacking="dense", showFeatureId=TRUE, id=c('red','blue', 'red'), fill=c('red','blue', 'red'))

> **Comments:**
> **username_0**: Thanks, seems to work, can't believe I missed that! What colours are accepted as arguments for `fill`?  
> **username_1**: Probably all colors, [here](http://sape.inf.usi.ch/quick-reference/ggplot2/colour) a list of color names.  
> **username_2**: @Chris_Rands see `?plotTracks` for the options accepted by `plotTracks` which will then refer you to `?settings` for the various things you can tweak (long, long documentation). Finally, `availableDisplayPars(track)` will show you what you can set for `track`.  

---

