This vignette demonstrates how to add covariate bars and use discrete color maps in a NG-CHM, and uses the sample data described in Create a NG-CHM.

Create a Covariate Bar

To start, the demo data, support files, and NGCHM-R package are loaded into the current R environment, and an initial NGCHM of the demo expression data is created with the chmNew() function.

library(NGCHMDemoData)
library(NGCHM)
hm <- chmNew('tcga-brca', TCGA.BRCA.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.

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

This covariate bar is then added to the NG-CHM created above with chmAddCovariateBar():

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

This NG-CHM can be exported to either a .ngchm or .html file.

library(NGCHMSupportFiles)
chmExportToFile(hm,'tcga-brca-covariates.ngchm')
chmExportToHTML(hm,'tcga-brca-covariates.html')

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, and a color map for the TP53 mutation data, which consists of two strings: ‘WT’ and ‘MUT’ can be created with explicit color names or hexidecimal codes:

mutationColorMap <- chmNewColorMap(c("WT","MUT"),c("cornflowerblue","lightcoral"))
## Or equivalently, because #6495ED and #f08080 are the hexidecimal color codes 
## for cornflowerblue and lightcoral, respectively:
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 (other colors)',TCGA.BRCA.TP53MutationData,mutationColorMap)

Finally, this covariate 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.

library(NGCHMSupportFiles)
chmExportToFile(hm,'tcga-brca-covariates.ngchm')
chmExportToHTML(hm,'tcga-brca-covariates.html')

Resulting NG-CHM

The resulting NG-CHM has both the original covariate bar with the default color map and the covariate bar (of the same data) with the cornflowerblue and lightcoral color map:

#> Warning: `includeHTML()` was provided a `path` that appears to be a complete HTML document.
#>  Path: /Users/runner/work/NGCHM-R/NGCHM-R/vignettes/tcga-brca-covariates.html
#>  Use `tags$iframe()` to include an HTML document. You can either ensure `path` is accessible in your app or document (see e.g. `shiny::addResourcePath()`) and pass the relative path to the `src` argument. Or you can read the contents of `path` and pass the contents to `srcdoc`.