AnnotationFunction: Constructor of AnnotationFunction Class

View source: R/AnnotationFunction-class.R

AnnotationFunctionR Documentation

Constructor of AnnotationFunction Class


Constructor of AnnotationFunction Class


AnnotationFunction(fun, fun_name = "", which = c("column", "row"), cell_fun = NULL,
    var_import = list(), n = NA, data_scale = c(0, 1), subset_rule = list(),
    subsettable = length(subset_rule) > 0, show_name = TRUE, width = NULL, height = NULL)



A function which defines how to draw the annotation. See **Details** section.


The name of the function. It is only used for printing the object.


Whether it is drawn as a column annotation or a row annotation?


A simplified version of fun. cell_fun only accepts one single index and it draws repeatedly in each annotation cell.


The names of the variables or the variable themselves that the annotation function depends on. See **Details** section.


Number of observations in the annotation. It is not mandatory, but it is better to provide this information so that the higher order HeatmapAnnotation knows it and it can perform check on the consistency of annotations and heatmaps.


The data scale on the data axis (y-axis for column annotation and x-axis for row annotation). It is only used when decorate_annotation is used with "native" unit coordinates.


The rule of subsetting variables in var_import. It should be set when users want the final object to be subsettable. See **Details** section.


Whether the object is subsettable?


It is used to turn off the drawing of annotation names in HeatmapAnnotation. Annotations always have names associated and normally they will be drawn beside the annotation graphics to tell what the annotation is about. e.g. the annotation names put beside the points annotation graphics. However, for some of the annotations, the names are not necessarily to be drawn, such as text annotations drawn by anno_text or an empty annotation drawn by anno_empty. In this case, when show_names is set to FALSE, there will be no annotation names drawn for the annotation.


The width of the plotting region (the viewport) that the annotation is drawn. If it is a row annotation, the width must be an absolute unit. Since the AnnotationFunction object is always contained by the SingleAnnotation-classobject, you can only set the width of row annotations or height of column annotations, while e.g. the height of the row annotation is always unit(1, "npc") which means it always fully filled in the parent SingleAnnotation and only in SingleAnnotation or even HeatmapAnnotation can adjust the height of the row annotations.


The height of the plotting region (the viewport) that the annotation is drawn. If it is a column annotation, the width must be an absolute unit.


In the package, we have implemted quite a lot annotation functions by AnnotationFunction constructor: anno_empty, anno_image, anno_points, anno_lines, anno_barplot, anno_boxplot, anno_histogram, anno_density, anno_joyplot, anno_horizon, anno_text and anno_mark. These built-in annotation functions support as both row annotations and column annotations and they are are all subsettable.

The build-in annotation functions are already enough for most of the analysis, nevertheless, if users want to know more about how to construct the AnnotationFunction class manually, they can refer to


A AnnotationFunction-class object which can be used in HeatmapAnnotation.


x = 1:10
anno1 = AnnotationFunction(
    fun = function(index, k, n) {
        n = length(index)
        pushViewport(viewport(xscale = c(0.5, n + 0.5), yscale = c(0, 10)))
        grid.points(1:n, x[index], default.units = "native")
        if(k == 1) grid.yaxis()
    var_import = list(x = x),
    n = 10,
    subsettable = TRUE,
    height = unit(2, "cm")
m = rbind(1:10, 11:20)
Heatmap(m, top_annotation = HeatmapAnnotation(foo = anno1))
Heatmap(m, top_annotation = HeatmapAnnotation(foo = anno1), column_km = 2)

jokergoo/ComplexHeatmap documentation built on Nov. 17, 2023, 11:27 a.m.