Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
90 lines (63 sloc) 2 KB
---
title: "Colors of Track"
---
Colors of features in a track can be specified with a character vector or a positive
integer vector which will be expanded to the same length of track data. The values will
be part of the track data and can be modified after the track is constructed.
```{r}
suppressPackageStartupMessages({
library(TnT)
library(GenomicFeatures)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
})
```
## R Color Names
This example shows all available color names in R with a block track.
```{r}
colors <- colors()
data <- GRanges("Unknown", IRanges(seq_along(colors), width = 2), "Color Name" = colors)
track <- TnT::BlockTrack(data, color = data$"Color Name", label = NULL)
TnT::TnTBoard(track)
```
<br/> <br/>
## Use Color Palettes
Colors can be also specified with a positive integer vector `i`, meaning `palette()[i]`,
as in R base graphics.
```{r}
data <- GRanges("Unknown", IRanges(1:6, width = 2), "Color" = 1:6)
track <- TnT::BlockTrack(data, color = data$"Color", label = NULL)
board <- TnT::TnTBoard(track, view.range = range(data))
board
```
You can use color palette to change the mapping of colors.
```{r}
grDevices::palette(grDevices::rainbow(6))
board
```
```{r}
grDevices::palette(grDevices::terrain.colors(6))
board
```
## Gene Colors
This example shows a gene track that genes have different colors based on their biotypes.
First is to get the data from EnsDb.
```{r}
suppressPackageStartupMessages(
library(EnsDb.Hsapiens.v75)
)
gene <- genes(EnsDb.Hsapiens.v75)
```
In the track constructor, specify the colors of features by converting the
`gene_biotype` to integer vector. Then set the color palette and build the
browser.
```{r}
genetrack <- TnT::FeatureTrack(gene, tooltip = as.data.frame(gene),
color = as.integer(factor(gene$gene_biotype)))
# Set color palette
palette(terrain.colors(length(unique(gene$gene_biotype))))
TnT::TnTGenome(genetrack, view.range = gene[gene$symbol == "BRCA2"][1] * .5)
```
## Session Info
```{r}
sessionInfo()
```