In addition to specifying color maps (see Color Maps), data layers allow for displaying multiple data sets in the same NG-CHM. This vignette describes how to create an NG-CHM with multiple data layers.
These examples build on the setup from Getting Started
Data Layers
The function chmNewDataLayer()
creates a data layer. 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.
The example below creates a color map and a data layer for the TCGA BRCA
Expression data. See Color Maps for more
information on creating color maps.
dataColorMap <- chmNewColorMap(c(6.4, 10, 14), c("mediumblue", "snow", "firebrick"))
dataLayer <- chmNewDataLayer("Unadjusted", matrix_data, dataColorMap)
For a second data layer, the data is row centered. The code block below row-centers the data, creates a color map, and creates a second data layer for the row-centered data.
rowCenteredData <- t(scale(t(matrix_data)))
rowCenteredColorMap <- chmNewColorMap(c(-2, 0, 2), c("#9933ff", "#f0f0f0", "#228B22"))
rowCenteredLayer <- chmNewDataLayer("Row-Centered", rowCenteredData, rowCenteredColorMap)
The NG-CHM can then be created with both data layers:
hm <- chmNew("TCGA BRCA Expression", dataLayer, rowCenteredLayer)
Resulting NG-CHM
Below is the full code block and resulting NG-CHM.
library(NGCHMDemoData)
library(NGCHMSupportFiles)
library(NGCHM)
matrix_data_file <- system.file("extdata", "TCGA.BRCA.Expression.csv", package = "NGCHMDemoData")
matrix_data <- as.matrix(read.csv(matrix_data_file, header = TRUE, row.names = 1, check.names = FALSE, stringsAsFactors = FALSE))
covariate_data_file <- system.file("extdata", "TCGA.BRCA.TP53Mutation.csv", package = "NGCHMDemoData")
covariate_data <- as.matrix(read.csv(covariate_data_file, row.names = 1, check.names = FALSE, stringsAsFactors = FALSE))
covariate_vector <- as.vector(covariate_data) # create vector of mutation data
names(covariate_vector) <- rownames(covariate_data) # set the names
dataColorMap <- chmNewColorMap(c(6.4, 10, 14), c("mediumblue", "snow", "firebrick"))
dataLayer <- chmNewDataLayer("Unadjusted", matrix_data, dataColorMap)
rowCenteredData <- t(scale(t(matrix_data)))
rowCenteredColorMap <- chmNewColorMap(c(-2, 0, 2), c("#9933ff", "#f0f0f0", "#228B22"))
rowCenteredLayer <- chmNewDataLayer("Row-Centered", rowCenteredData, rowCenteredColorMap)
hm <- chmNew("TCGA BRCA Expression", dataLayer, rowCenteredLayer)
chmExportToHTML(hm, "datalayers.html", overwrite = TRUE)
htmltools::tags$iframe(src = "datalayers.html", width = "100%", height = 700)
The resulting NG-CHM has the two data layers available. To toggle between layers, click the icon (the first of the 4 buttons on the upper right side).