AnnotationFunction: Constructor of AnnotationFunction Class

Description Usage Arguments Details Value Examples

View source: R/AnnotationFunction-class.R

Description

Constructor of AnnotationFunction Class

Usage

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

Arguments

fun

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

fun_name

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

which

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

var_import

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

n

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.

data_scale

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.

subset_rule

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

subsetable

Whether the object is subsetable?

show_name

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.

width

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.

height

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.

Details

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 https://jokergoo.github.io/ComplexHeatmap-reference/book/heatmap-annotations.html#implement-new-annotation-functions.

Value

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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.rect()
        grid.points(1:n, x[index], default.units = "native")
        if(k == 1) grid.yaxis()
        popViewport()
    },
    var_import = list(x = x),
    n = 10,
    subsetable = 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)

Example output

Loading required package: grid
========================================
ComplexHeatmap version 2.6.2
Bioconductor page: http://bioconductor.org/packages/ComplexHeatmap/
Github page: https://github.com/jokergoo/ComplexHeatmap
Documentation: http://jokergoo.github.io/ComplexHeatmap-reference

If you use it in published research, please cite:
Gu, Z. Complex heatmaps reveal patterns and correlations in multidimensional 
  genomic data. Bioinformatics 2016.

This message can be suppressed by:
  suppressPackageStartupMessages(library(ComplexHeatmap))
========================================

ComplexHeatmap documentation built on Nov. 14, 2020, 2:01 a.m.