ExperimentColorMap-class | R Documentation |
ExperimentColorMap class
ExperimentColorMap(
assays = list(),
colData = list(),
rowData = list(),
all_discrete = list(assays = NULL, colData = NULL, rowData = NULL),
all_continuous = list(assays = NULL, colData = NULL, rowData = NULL),
global_discrete = NULL,
global_continuous = NULL,
...
)
assays |
List of colormaps for |
colData |
List of colormaps for |
rowData |
List of colormaps for |
all_discrete |
Colormaps applied to all undefined
categorical |
all_continuous |
Colormaps applied to all undefined
continuous |
global_discrete |
Colormap applied to all undefined categorical covariates. |
global_continuous |
Colormap applied to all undefined continuous covariates. |
... |
additional arguments passed on to the |
Colormaps must all be functions that take at least one argument: the number
of (named) colours to return as a character
vector.
This argument may be ignored in the body of the colormap function
to produce constant colormaps.
An object of class ExperimentColorMap
The default categorical colormap emulates the default ggplot2 categorical color palette (Credit: https://stackoverflow.com/questions/8197559/emulate-ggplot2-default-color-palette). This palette returns a set of colors sampled in steps of equal size that correspond to approximately equal perceptual changes in color:
function(n) { hues=seq(15, 375, length=(n + 1)) hcl(h=hues, l=65, c=100)[seq_len(n)] }
To change the palette for all categorical variables,
users must supply a colormap that returns a similar value;
namely, an unnamed character vector of length n
.
For instance, using the base R palette rainbow.colors
function(n) { rainbow(n) }
In the following code snippets, x
is an ExperimentColorMap
object.
assayColorMap(x, i, ..., discrete=FALSE)
:Get an assays
colormap for the specified assay i
.
colDataColorMap(x, i, ..., discrete=FALSE)
:Get a colData
colormap for the specified colData
column i
.
rowDataColorMap(x, i, ..., discrete=FALSE)
:Get a rowData
colormap for the specified rowData
column i
.
If the colormap for i
cannot be found, one of the default colormaps is returned.
In this case, discrete
is a logical scalar that indicates whether the colormap should be categorical.
The more specialized default is first attempted -
e.g., for assayColorMap
, this would be the assay colormap specified in assays
of all_discrete
or all_continuous
-
before falling back to the global default in global_discrete
or global_continuous
.
Similarly, if i
is missing, the default discrete/continuous colormap is returned.
In the following code snippets, x
is an ExperimentColorMap
object,
and i
is a character or numeric index.
assayColorMap(x, i, ...) <- value
:Set an assays
colormap.
colDataColorMap(x, i, ...) <- value
:Set a colData
colormap.
rowDataColorMap(x, i, ...) <- value
:Set a rowData
colormap.
assay(x, i, ...) <- value
:Alias. Set an assays
colormap.
# Example colormaps ----
count_colors <- function(n){
c("black", "brown", "red", "orange", "yellow")
}
fpkm_colors <- viridis::inferno
tpm_colors <- viridis::plasma
qc_color_fun <- function(n){
qc_colors <- c("forestgreen", "firebrick1")
names(qc_colors) <- c("Y", "N")
return(qc_colors)
}
# Constructor ----
ecm <- ExperimentColorMap(
assays=list(
counts=count_colors,
tophat_counts=count_colors,
cufflinks_fpkm=fpkm_colors,
rsem_tpm=tpm_colors
),
colData=list(
passes_qc_checks_s=qc_color_fun
)
)
# Accessors ----
# assay colormaps
assayColorMap(ecm, "logcounts") # [undefined --> default]
assayColorMap(ecm, "counts")
assayColorMap(ecm, "cufflinks_fpkm")
assay(ecm, "cufflinks_fpkm") # alias
# colData colormaps
colDataColorMap(ecm, "passes_qc_checks_s")
colDataColorMap(ecm, "undefined")
# rowData colormaps
rowDataColorMap(ecm, "undefined")
# generic accessors
assays(ecm)
assayNames(ecm)
# Setters ----
assayColorMap(ecm, "counts") <- function(n){c("blue", "white", "red")}
assay(ecm, 1) <- function(n){c("blue", "white", "red")}
colDataColorMap(ecm, "passes_qc_checks_s") <- function(n){NULL}
rowDataColorMap(ecm, "undefined") <- function(n){NULL}
# Categorical colormaps ----
# Override all discrete colormaps using the base rainbow palette
ecm <- ExperimentColorMap(global_discrete = rainbow)
n <- 10
plot(1:n, col=assayColorMap(ecm, "undefined", discrete = TRUE)(n), pch=20, cex=3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.