### Department of Bioinformatics and Computational Biology

Home > Public Software > NG-CHM R > Continuous Color Maps and Data Layers

## Continuous Color Maps and Data Layers

This vignette demonstrates how to use custom color maps in a NG-CHM.

In this example, we create a NG-CHM from the sample data described in the Create a NG-CHM page. On that page, the NG-CHM was created directly from a matrix of data. Since no color map was specified, a default color map was used. This vignette demonstrates how to specify the color map by creating a NG-CHM from 2 data layers and 2 custom color maps.

First we load the following libraries:

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

We create a color map with chmNewColorMap(). The first argument to this function is a list of breakpoints. For the demo data in TCGA.GBM.ExpressionData, most values are between -2 and 2, so we set breakpoints at -2, 0, and 2. The second argument is a corresponding list of colors for those breakpoints. The colors can be specified by name for standard colors, or by hexadecimal code.

colorMap1 <- chmNewColorMap(c(-2,0,2), c('mediumblue','snow','firebrick'))

A data layer can be created with the chmNewDataLayer() function. The first argument is the desired name of the data layer. The second argument is the matrix of data, and the third argument is the color map created above.

dataLayer1 <- chmNewDataLayer('Color Map 1', TCGA.GBM.ExpressionData, colorMap1)

For demonstration purposes, we create a second color map with the same breakpoints going from purple to green, this time using hexadecimal color codes,

colorMap2 <- chmNewColorMap(c(-2,0,2), c('#9933ff','#f0f0f0','#228B22'))

and a data layer from this color map using the same data

dataLayer2 <- chmNewDataLayer('Color Map 2', TCGA.GBM.ExpressionData, colorMap2)

In the Create a NG-CHM page, the chmNew() function’s arguments were the desired name of the NG-CHM, and a matrix of data. In that example, the chmNew() function converted the matrix of data into a data layer and applied a default color map. Here we explicitly provide the two data layers created above,

hm <- chmNew('Color Maps', dataLayer1, dataLayer2)

and export to a .ngchm or .html file:

chmExportToFile(hm,'color-map.ngchm',overwrite=TRUE)
chmExportToHTML(hm,'color-map.html',overwrite=TRUE)

When opening the file ‘color-map.ngchm’ in the NG-CHM Viewer , or opening the stand-alone ‘color-map.html’ file, the data layers will be available from the data layer icon.