### Department of Bioinformatics and Computational Biology

Home > Public Software > NG-CHM R > Covariate Bars and Discrete Color Maps

## Covariate Bars and Discrete Color Maps

This vignette demonstrates how to add covariate bars to a NG-CHM, and uses the sample data described in the Create a NG-CHM page. This vignette contains the following sections:

### Create a Covariate Bar

To start, the demo data, support files, and NGCHM-R package are loaded into the current R environment.

library(NGCHMDemoData)
library(NGCHMSupportFiles)
library(NGCHM)

An initial NGCHM of the demo expression data created with the chmNew() function. The first argument is the desired name of the NG-CHM, and the second is the matrix of gene expression demo data described in the Create a NG-CHM page.

hm <- chmNew('tcga-gbm', TCGA.GBM.ExpressionData)

A covariate bar can be created from the TP53 mutation vector using the chmNewCovariate() function. The first argument is the desired name of the covariate bar, and the second is the vector of TP53 mutation demo data described in the Create a NG-CHM page.

covariateBar <- chmNewCovariate('TP53 Mutation',TCGA.GBM.TP53MutationData)

This covariate bar is then added to the NG-CHM created above with chmAddCovariateBar(). The first argument is the NG-CHM, hm. The second is the desired axis for the covariate (either ‘row’ or ‘column’); here a column covariate. The third argument is the covariate bar created directly above, covariateBar.

hm <- chmAddCovariateBar(hm, 'column', covariateBar)

As described in the Create a NG-CHM page, this NG-CHM can be exported to either a .ngchm or .html file.

chmExportToFile(hm,'tcga-gbm.ngchm',overwrite=TRUE)
chmExportToHTML(hm,'tcga-gbm.html',overwrite=TRUE)

### Specify Covariate Bar Color Map

In the section above, the color map for the ‘TP53 Mutation’ covariate bar was not specified, and the NGCHM-R package generated one automatically. However a color map can be explicitly constructed, as shown below.

The TP53 mutation data values consist of two discrete strings: ‘WT’ denoting wild type, and ‘MUT’ denoting mutation. The chmNewColorMap() function is used for creating a color map. The first argument is a list of the discrete values in the data, here ‘WT’ and ‘MUT’. The second argument is a corresponding list of colors. These colors can be explicit names for colors available in R, or a hexadecimal color code.

This example specifies the color map with color names:

mutationColorMap <- chmNewColorMap(c("WT","MUT"),c("cornflowerblue","lightcoral"))

and here is the same example using hexadecimal color codes:

mutationColorMap <- chmNewColorMap(c("WT","MUT"),c("#6495ED","#f08080"))

In the chmNewCovariate() function (also used above), an optional third argument is a color map:

covariateBar <- chmNewCovariate('TP53 Mutation',TCGA.GBM.TP53MutationData,mutationColorMap)

Finally, this new color bar can be added to the NG-CHM created above,

hm <- chmAddCovariateBar(hm,'column',covariateBar)

As described in the Create a NG-CHM page, this NG-CHM can be exported to either a .ngchm or .html file.

chmExportToFile(hm,'tcga-gbm.ngchm',overwrite=TRUE)
chmExportToHTML(hm,'tcga-gbm.html',overwrite=TRUE)