Learn R Programming

ComplexHeatmap (version 1.10.2)

SingleAnnotation: Constructor method for SingleAnnotation class

Description

Constructor method for SingleAnnotation class

Usage

SingleAnnotation(name, value, col, fun,
    na_col = "grey",
    which = c("column", "row"),
    show_legend = TRUE,
    gp = gpar(col = NA),
    legend_param = list())

Arguments

name
name for this annotation. If it is not specified, an internal name is assigned.
value
A vector of discrete or continuous annotation.
col
colors corresponding to value. If the mapping is discrete mapping, the value of col should be a vector; If the mapping is continuous mapping, the value of col should be a color mapping function.
fun
a self-defined function to add annotation graphics. The argument of this function should only be a vector of index that corresponds to rows or columns.
na_col
color for NA values in simple annotations.
which
is the annotation a row annotation or a column annotation?
show_legend
if it is a simple annotation, whether show legend when making the complete heatmap.
gp
Since simple annotation is represented as a row of grids. This argument controls graphic parameters for the simple annotation.
legend_param
parameters for the legend. See color_mapping_legend,ColorMapping-method for options.

Value

Details

The most simple annotation is one row or one column grids in which different colors represent different classes of the data. Here the function use ColorMapping-class to process such simple annotation. value and col arguments controls values and colors of the simple annotation and a ColorMapping-class object will be constructed based on value and col.

fun is used to construct a more complex annotation. Users can add any type of annotation graphics by implementing a function. The only input argument of fun is a index of rows or columns which is already adjusted by the clustering. In the package, there are already several annotation graphic function generators: anno_points, anno_histogram and anno_boxplot.

In the case that row annotations are splitted by rows, index corresponding to row orders in each row-slice and fun will be applied on each of the row slices.

One thing that users should be careful is the difference of coordinates when the annotation is a row annotation or a column annotation.

See Also

There are following built-in annotation functions that can be used to generate complex annotations: anno_points, anno_barplot, anno_histogram, anno_boxplot, anno_density, anno_text and anno_link.

Examples

Run this code
# discrete character
SingleAnnotation(name = "test", value = c("a", "a", "a", "b", "b", "b"))
SingleAnnotation(name = "test", value = c("a", "a", "a", "b", "b", "b"), 
    which = "row")

# with defined colors
SingleAnnotation(value = c("a", "a", "a", "b", "b", "b"), 
    col = c("a" = "red", "b" = "blue"))

# continuous numbers
require(circlize)
SingleAnnotation(value = 1:10)
SingleAnnotation(value = 1:10, col = colorRamp2(c(1, 10), c("blue", "red")))

# self-defined graphic function
SingleAnnotation(fun = anno_points(1:10))

Run the code above in your browser using DataLab