### Calculate Set Sizes using set_size Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/set_size.html This example demonstrates how to use the set_size function to get the sizes of sets from a combination matrix. Ensure you have created a combination matrix using make_comb_mat first. ```R set.seed(123) lt = list(a = sample(letters, 10), b = sample(letters, 15), c = sample(letters, 20)) m = make_comb_mat(lt) set_size(m) ``` -------------------------------- ### Get Column Order from a Heatmap Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/column_order-Heatmap-method.html This example shows how to create a Heatmap, draw it, and then retrieve the column order. Use this when you need to know the arrangement of columns after the heatmap has been rendered. ```R mat = matrix(rnorm(100), 10) ht = Heatmap(mat) ht = draw(ht) column_order(ht) ``` -------------------------------- ### Create a Heatmap List Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/Extract.HeatmapList.rd Creates a basic heatmap list with a single heatmap generated from random data. This serves as a starting point for extraction examples. ```r ht_list = Heatmap(matrix(runif(100), 10), name = "runif") ``` -------------------------------- ### Negative Values from Top Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/anno_horizon.rd This example illustrates how to display negative values starting from the top of the annotation area. ```APIDOC ## anno_horizon with Negative Values from Top ### Description Shows how to configure horizon charts so that negative values originate from the top of the annotation area. ### Arguments - `lt`: A list of time series data. - `which`: Specifies whether to annotate 'row' or 'column'. - `negative_from_top`: Logical, if TRUE, negative values are drawn from the top. ### Example ```R lt <- lapply(1:20, function(x) cumprod(1 + runif(1000, -x/100, x/100))) - 1 anno <- anno_horizon(lt, which = "row", negative_from_top = TRUE) draw(anno, test = "horizon chart + negative_from_top") ``` ``` -------------------------------- ### Basic Usage Example Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/grid.dendrogram.rd Demonstrates how to create a dendrogram and draw it using grid.dendrogram. ```APIDOC ## Basic Dendrogram Drawing ### Description This example shows the basic usage of `grid.dendrogram` after setting up a grid viewport. ### Code ```R m = matrix(rnorm(100), 10) dend = as.dendrogram(hclust(dist(m))) grid.newpage() pushViewport(viewport(xscale = c(0, 10.5), yscale = c(0, dend_heights(dend)), width = 0.9, height = 0.9)) grid.dendrogram(dend) popViewport() ``` ``` -------------------------------- ### Example: Create Image Annotation with Sampled Images Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/anno_image.rd This example demonstrates how to use anno_image by first sampling image file paths from a directory. It's important to ensure the directory contains images in supported formats (png, svg, pdf, eps, jpeg/jpg, tiff). The code is wrapped in `if (FALSE)` to prevent execution during standard package checks. ```R # download the free icons from https://github.com/Keyamoon/IcoMoon-Free if (FALSE) { image = sample(dir("~/Downloads/IcoMoon-Free-master/PNG/64px", full.names = TRUE), 10) anno = anno_image(image) ``` -------------------------------- ### Basic Heatmap Setup Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/decorate_annotation.html Sets up a basic heatmap with row and column annotations. This is a prerequisite for decorating annotations. ```R set.seed(123) ha1 = HeatmapAnnotation(df = data.frame(type = rep(letters[1:2], 5))) ha2 = rowAnnotation(point = anno_points(runif(10), which = "row")) Heatmap(matrix(rnorm(100), 10), name = "mat", km = 2, top_annotation = ha1) + ha2 ``` -------------------------------- ### Get Column Order with Split Columns Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/column_order-Heatmap-method.html This example demonstrates retrieving column orders when the heatmap columns are split into clusters. The output will be a list where each element corresponds to a cluster and contains the column order for that cluster. ```R mat = matrix(rnorm(100), 10) ht = Heatmap(mat, column_km = 2) ht = draw(ht) column_order(ht) ``` -------------------------------- ### Input: List of Sets Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/make_comb_mat.rd Example of how to represent input sets as a list, where each element of the list is a vector representing a set. ```R list(set1 = c("a", "b", "c"), set2 = c("b", "c", "d", "e"), ...) ``` -------------------------------- ### Basic anno_boxplot Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/anno_boxplot.rd This example shows how to create a basic boxplot annotation using anno_boxplot with a specified height. ```APIDOC ## anno_boxplot ### Description Creates a boxplot annotation for a heatmap. ### Arguments - **m**: A matrix object. - **height**: The height of the annotation. Defaults to `unit(4, "cm")`. ### Examples ```r anno <- anno_boxplot(m, height = unit(4, "cm")) draw(anno, test = "anno_boxplot") ``` ``` -------------------------------- ### Width Methods Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/index.html Methods for getting and setting the width of various objects. ```APIDOC ## width() ### Description Width of the AnnotationFunction Object. ### Endpoint width.AnnotationFunction.html ``` ```APIDOC ## width() ### Description Width of the Heatmap. ### Endpoint width.Heatmap.html ``` ```APIDOC ## width() ### Description Width of the HeatmapAnnotation Object. ### Endpoint width.HeatmapAnnotation.html ``` ```APIDOC ## width() ### Description Width of the HeatmapList. ### Endpoint width.HeatmapList.html ``` ```APIDOC ## width() ### Description Width of the Legends. ### Endpoint width.Legends.html ``` ```APIDOC ## width() ### Description Width of the SingleAnnotation Object. ### Endpoint width.SingleAnnotation.html ``` ```APIDOC ## `width<-`() ### Description Assign the Width to the AnnotationFunction Object. ### Endpoint widthAssign.AnnotationFunction.html ``` ```APIDOC ## `width<-`() ### Description Assign the Width to the HeatmapAnnotation Object. ### Endpoint widthAssign.HeatmapAnnotation.html ``` ```APIDOC ## `width<-`() ### Description Assign the Width to the SingleAnnotation Object. ### Endpoint widthAssign.SingleAnnotation.html ``` -------------------------------- ### Test Mode Example Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/grid.dendrogram.rd Illustrates the usage of grid.dendrogram with the test argument set to TRUE. ```APIDOC ## Dendrogram Drawing in Test Mode ### Description This example demonstrates drawing a dendrogram with the `test` argument set to TRUE, which affects viewport creation. ### Code ```R m = matrix(rnorm(100), 10) dend = as.dendrogram(hclust(dist(m))) # Assuming grid.newpage() and pushViewport() have been called appropriately grid.dendrogram(dend, test = TRUE) ``` ``` -------------------------------- ### Basic Usage of anno_text Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/anno_text.rd Example of creating a basic text annotation using month names. ```APIDOC ## Basic Text Annotation ### Description This example demonstrates the basic usage of the `anno_text` function to create a text annotation with default settings. ### Code ```R anno <- anno_text(month.name) draw(anno, test = "month names") ``` ``` -------------------------------- ### Get Width of Row Annotation Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/width.AnnotationFunction.rd This example demonstrates how to get the width of a row annotation object. The width is returned in 'npc' units. ```r anno = 1:10 ComplexHeatmap:::width(anno) ``` -------------------------------- ### Verify pindex output with identical Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/pindex.rd This example demonstrates how to use the identical function to verify the output of pindex against a manually constructed matrix. It's useful for testing the correctness of pindex. ```R identical(pindex(arr, 1:2, 2:3), rbind(arr[1, 2, ], arr[2, 3, ])) ``` -------------------------------- ### List Components Function Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/list_components.rd Call the list_components function to get a vector of viewport names. There are no examples provided in the documentation for this function. ```r list_components() ``` -------------------------------- ### Get Width of Column Annotation Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/width.AnnotationFunction.rd This example shows how to retrieve the width of a column annotation object. The width is returned in 'cm' units. ```r anno = 1:10, which = "row" ComplexHeatmap:::width(anno) ``` -------------------------------- ### Initialize HeatmapList and Draw Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/column_order-HeatmapList-method.rd Create a HeatmapList with two heatmaps and draw it. This is a prerequisite for retrieving column order. ```R mat = matrix(rnorm(100), 10) ht_list = Heatmap(mat) + Heatmap(mat) ht_list = draw(ht_list) ``` -------------------------------- ### Get Row Dendrograms from a Basic Heatmap Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/row_dend-Heatmap-method.html This example shows how to create a heatmap and then retrieve its row dendrogram. The dendrogram is returned as an object of class 'dendrogram'. ```R mat = matrix(rnorm(100), 10) ht = Heatmap(mat) ht = draw(ht) row_dend(ht) ``` -------------------------------- ### smartAlign2 with Randomized Data Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/smartAlign2.rd Illustrates using smartAlign2 with a larger dataset that includes randomized noise. This example shows how the function handles more complex and slightly varied input, suitable for real-world scenarios. ```R pos1 <- rbind(c(-1, 2), c(3, 4), c(5, 6), c(7, 11)) pos1 <- pos1 + runif(length(pos1), max = 0.3, min = -0.3) omfrow <- par("mfrow") par(mfrow = c(3, 3)) for(i in 1:9) { ind <- sample(4, 4) make_plot(pos1[ind, ], smartAlign2(pos1[ind, ], range = range), range) } par(mfrow = omfrow) ``` -------------------------------- ### Get Row Dendrograms from a Split Heatmap Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/row_dend-Heatmap-method.html This example demonstrates retrieving row dendrograms when the heatmap rows are split into multiple clusters (row_km). The output will show dendrograms for each split. ```R mat = matrix(rnorm(100), 10) ht = Heatmap(mat, row_km = 2) ht = draw(ht) row_dend(ht) ``` -------------------------------- ### Initialize HeatmapList with Vertical Combination and Column Clustering Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/column_dend-HeatmapList-method.rd Demonstrates initializing a HeatmapList with vertical combination and column clustering. This setup is useful for preparing complex heatmap visualizations where column clustering is a key feature. ```r mat = matrix(rnorm(100), 10) ht_list = Heatmap(mat, column_km = 2) %v% Heatmap(mat) ``` -------------------------------- ### Basic Horizon Annotation Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/anno_horizon.rd This example demonstrates the basic usage of anno_horizon to create row annotations using horizon charts. ```APIDOC ## anno_horizon ### Description Creates horizon charts for row annotations. ### Arguments - `lt`: A list of time series data. - `which`: Specifies whether to annotate 'row' or 'column'. ### Details This function is part of the complexheatmap package for creating advanced visualizations. ### Value An annotation object that can be drawn using the `draw` function. ### Example ```R lt <- lapply(1:20, function(x) cumprod(1 + runif(1000, -x/100, x/100))) - 1 anno <- anno_horizon(lt, which = "row") draw(anno, test = "horizon chart") ``` ``` -------------------------------- ### Basic Heatmap with Annotation Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/AnnotationFunction.rd Demonstrates creating a heatmap with a top annotation using the Heatmap and HeatmapAnnotation functions. ```APIDOC ## Heatmap with Top Annotation ### Description Creates a heatmap with specified top annotations. ### Method Function Call ### Endpoint N/A (R function) ### Parameters - **m**: The input data matrix for the heatmap. - **top_annotation**: A HeatmapAnnotation object defining the top annotations. ### Request Example ```R Heatmap(m, top_annotation = HeatmapAnnotation(foo = anno1)) ``` ### Response N/A (R function returns a heatmap object) ``` -------------------------------- ### Cluster within and between Groups using cluster_within_group Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/cluster_within_group.html This example demonstrates how to use the cluster_within_group function to cluster columns of a matrix based on a categorical factor. It then visualizes the resulting dendrogram. Ensure the ComplexHeatmap package is installed and loaded. ```R m = matrix(rnorm(120), nc = 12) colnames(m) = letters[1:12] fa = rep(c("a", "b", "c"), times = c(2, 4, 6)) dend = cluster_within_group(m, fa) grid.dendrogram(dend, test = TRUE) ``` -------------------------------- ### Initialize HeatmapList with Column Clustering and Draw Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/column_order-HeatmapList-method.rd Create a HeatmapList with two heatmaps, each with column clustering (column_km = 2), and then draw it. This setup is necessary to observe split column orders. ```R ht_list = Heatmap(mat, column_km = 2) + Heatmap(mat, column_km = 2) ht_list = draw(ht_list) ``` -------------------------------- ### Display heatmap with labeled row annotation Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/anno_mark.html Renders a heatmap with an integrated row annotation that includes labels and connecting lines. This example demonstrates how to add the annotation directly during heatmap creation, simplifying the visualization setup. ```R [Heatmap](Heatmap.html)(m) + [rowAnnotation](rowAnnotation.html)(mark = anno) ``` -------------------------------- ### Create a matrix and extract values using pindex Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/pindex.html Demonstrates how to create a matrix, identify indices where values are greater than 0, and then use `pindex` to retrieve these specific values. It also verifies that the extracted values are identical to the original filtered values. ```R m = matrix(rnorm(100), 10) m2 = m[m > 0] ind = do.call("rbind", lapply(1:10, function(ci) { i = which(m[, ci] > 0) cbind(i = i, j = rep(ci, length(i))) })) pindex(m, ind[, 1], ind[, 2]) #> [1] 0.31030923 0.66651132 0.45825713 1.23923784 0.32142619 1.98665079 #> [7] 1.88720053 0.66381092 0.73569713 0.60318930 0.54504614 0.65076758 #> [13] 0.30038830 1.41536821 0.73609075 0.58291632 0.51167333 0.81057520 #> [19] 1.01772098 0.59880248 1.01672953 0.04375947 0.97048785 0.87070062 #> [25] 0.47912409 0.57563890 1.54384492 1.83154531 0.63925483 0.46531229 #> [31] 0.19790749 0.25733554 0.16704424 0.29074462 0.87210366 2.28670551 #> [37] 0.52292860 2.27514007 0.87646511 2.21329543 1.71954343 1.11922942 #> [43] 0.49667542 0.21108201 0.86968687 1.07345732 0.40879306 0.78597642 #> [49] 2.15207805 0.72119043 0.02362363 identical(pindex(m, ind[, 1], ind[, 2]), m[m > 0]) #> [1] TRUE ``` -------------------------------- ### Get Row Dendrograms with Row Clustering Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/row_dend-HeatmapList-method.rd This example shows how to retrieve row dendrograms when row clustering has been applied to one of the heatmaps in the HeatmapList. It creates a HeatmapList with one heatmap having row clustering and then draws it before extracting the dendrograms. ```R mat = matrix(rnorm(100), 10) ht_list = Heatmap(mat, row_km = 2) + Heatmap(mat) ht_list = draw(ht_list) row_dend(ht_list) ``` -------------------------------- ### Install ComplexHeatmap from Bioconductor Source: https://github.com/jokergoo/complexheatmap.git/blob/master/README.md Install the ComplexHeatmap package using BiocManager. Ensure BiocManager is installed first if it's not already. ```r if (!requireNamespace("BiocManager", quietly=TRUE)) install.packages("BiocManager") BiocManager::install("ComplexHeatmap") ``` -------------------------------- ### prepare Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/index.html Prepare the heatmap for drawing. ```APIDOC ## prepare ### Description Prepare the heatmap for drawing. ### Method `prepare(__)` ``` -------------------------------- ### Basic Legend Creation Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/Legend.html This example demonstrates how to create a basic legend using a color ramp function and draw it. ```APIDOC ## Legend Creation and Drawing ### Description Creates a legend with a specified color function and title, then draws it. ### Method This is an R code example demonstrating the usage of the Legend function. ### Endpoint N/A (R function) ### Parameters #### Arguments - `col_fun`: A color ramp function (e.g., created with `colorRamp2`). - `title`: The title of the legend. ### Request Example ```R col_fun <- colorRamp2(c(0, 0.5, 1), c("blue", "white", "red")) lgd <- Legend(col_fun = col_fun, title = "foo") draw(lgd, test = "only col_fun") ``` ### Response #### Success Response Displays a legend based on the provided `col_fun` and `title`. #### Response Example (Image reference: Legend-2.png) ``` -------------------------------- ### Install ComplexHeatmap from Bioconductor Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/index.html Installs the ComplexHeatmap package using BiocManager. Ensure BiocManager is installed first if it's not already. ```r if (!requireNamespace("BiocManager", quietly=TRUE)) install.packages("BiocManager") BiocManager::install("ComplexHeatmap") ``` -------------------------------- ### Convert Coordinates to Parent Viewport Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/getXY_in_parent_vp.rd This example demonstrates how to convert coordinates from the current viewport to the parent viewport using getXY_in_parent_vp. It sets up a new page, pushes a viewport, draws elements, converts coordinates, pops the viewport, and then draws points using the converted coordinates. ```R grid.newpage() pushViewport(viewport(x = 0.5, y = 0.5, width = 0.5, height = 0.5, just = c("left", "bottom"))) ``` ```R grid.rect() ``` ```R grid.points(x = unit(2, "cm"), y = unit(2, "cm"), pch = 1) ``` ```R u = list(x = unit(2, "cm"), y = unit(2, "cm")) u2 = getXY_in_parent_vp(u) ``` ```R popViewport() ``` ```R grid.rect(gp = gpar(col = "red")) ``` ```R grid.points(x = u2$x, u2$y, pch = 2) ``` -------------------------------- ### Get Width of Column Annotation Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/width.AnnotationFunction.html Demonstrates how to get the width of a column annotation using `ComplexHeatmap:::width`. The result is in 'npc'. ```R anno = anno_points(1:10) ComplexHeatmap:::width(anno) ``` -------------------------------- ### Get Width of Row Annotation Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/width.AnnotationFunction.html Demonstrates how to get the width of a row annotation using `ComplexHeatmap:::width`. The result is in 'cm'. ```R anno = anno_points(1:10, which = "row") ComplexHeatmap:::width(anno) ``` -------------------------------- ### Add text annotations with rotation, justification, and font sizes Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/anno_text.rd This example demonstrates adding text annotations with rotation, right justification, and varying font sizes. The `location` is set to 1, `rot` to 45, `just` to "right", and font sizes are adjusted using `gpar`. ```R anno = anno_text(month.name, location = 1, rot = 45, just = "right", gp = gpar(fontsize = 1:12 + 4)) draw(anno, test = "with rotations") ``` -------------------------------- ### Get Number of Observations for AnnotationFunction Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/nobs.AnnotationFunction.html Demonstrates how to get the number of observations from an AnnotationFunction object. This is useful for understanding the scale of the annotation. ```R anno <- anno_points(1:10) nobs(anno) ``` -------------------------------- ### Get Annotation Names Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/names.HeatmapAnnotation.html This snippet demonstrates how to use the `names()` function to get the names of annotations that have been added to a `HeatmapAnnotation` object. ```APIDOC ## Get Annotation Names ### Description Retrieves the names of the annotations associated with a `HeatmapAnnotation` object. ### Method `names(x)` ### Parameters #### Path Parameters * **x** (`HeatmapAnnotation-class`) - Required - A `HeatmapAnnotation` object. ### Examples ```R # Create a HeatmapAnnotation object ha <- HeatmapAnnotation(foo = 1:10, bar = anno_points(10:1)) # Get the names of the annotations annotation_names <- names(ha) # Print the names print(annotation_names) # Expected output: [1] "foo" "bar" ``` ### Response #### Success Response - **annotation_names** (character) - A character vector containing the names of the annotations. ``` -------------------------------- ### Create a Single Heatmap with ComplexHeatmap Source: https://context7.com/jokergoo/complexheatmap.git/llms.txt Demonstrates how to create a single heatmap using the `Heatmap()` constructor. It includes configurations for color mapping, row/column splitting, clustering, and custom cell-level graphics. Ensure `ComplexHeatmap` and `circlize` libraries are loaded. ```r library(ComplexHeatmap) library(circlize) set.seed(42) mat <- matrix(rnorm(200), nrow = 20, ncol = 10) rownames(mat) <- paste0("Gene", 1:20) colnames(mat) <- paste0("Sample", 1:10) # Continuous color mapping col_fun <- colorRamp2(c(-3, 0, 3), c("blue", "white", "red")) # Row metadata for split row_group <- rep(c("Group_A", "Group_B"), each = 10) ht <- Heatmap( mat, name = "Expression", # legend title col = col_fun, column_title = "Samples", row_title = "Genes", row_split = row_group, # split rows by group column_km = 2, # k-means split on columns cluster_rows = TRUE, cluster_columns = TRUE, clustering_distance_rows = "pearson", clustering_distance_columns = "euclidean", show_row_names = TRUE, show_column_names = TRUE, row_names_gp = gpar(fontsize = 8), column_names_rot = 45, border = TRUE, na_col = "grey50", heatmap_legend_param = list( title = "Z-score", at = c(-3, -1, 0, 1, 3), legend_height = unit(4, "cm") ), # Add per-cell value labels cell_fun = function(j, i, x, y, width, height, fill) { if (abs(mat[i, j]) > 2) grid.text(sprintf("%.1f", mat[i, j]), x, y, gp = gpar(fontsize = 7, col = "black")) } ) draw(ht, heatmap_legend_side = "right", annotation_legend_side = "right", padding = unit(c(5, 5, 5, 5), "mm")) # Retrieve clustering results after drawing ht_drawn <- draw(ht) row_ord <- row_order(ht_drawn) # list of row indices per slice col_ord <- column_order(ht_drawn) ``` -------------------------------- ### Create and Draw Image Annotation Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/anno_image.rd Demonstrates how to create an image annotation using anno_image and then draw it on a heatmap. The 'test' argument in draw can be used to specify output format or other drawing parameters. ```R image[1:5] = "" an_image = anno_image(image) draw(an_image, test = "png") ``` ```R draw(an_image, test = "some of png") ``` -------------------------------- ### Install Latest ComplexHeatmap from GitHub Source: https://github.com/jokergoo/complexheatmap.git/blob/master/README.md Install the latest development version of ComplexHeatmap directly from its GitHub repository using the devtools package. ```r library(devtools) install_github("jokergoo/ComplexHeatmap") ``` -------------------------------- ### Get Size of Column AnnotationFunction Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/size.AnnotationFunction.html Demonstrates how to get the size of a column annotation function. The size function returns the height for column annotations. ```r anno <- ComplexHeatmap:::anno_points(1:10, which = "row") ComplexHeatmap:::size(anno) ``` -------------------------------- ### Create Heatmap with Annotations Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/decorate_annotation.rd Sets up a heatmap with both column and row annotations. This is a prerequisite for decorating specific annotations. ```R set.seed(123) ha1 = HeatmapAnnotation( df = data.frame(type = rep(letters[1:2], 5)) ) ha2 = rowAnnotation(point = anno_points(runif(10), which = "row")) Heatmap(matrix(rnorm(100), 10), name = "mat", km = 2, top_annotation = ha1) + ha2 ``` -------------------------------- ### Basic Heatmap Creation Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/decorate_dimnames.html Sets up a matrix and creates a basic heatmap with 2 clusters. This serves as a base for applying decorations. ```R set.seed(123) mat = matrix(rnorm(100), 10) rownames(mat) = letters[1:10] colnames(mat) = LETTERS[1:10] Heatmap(mat, name = "mat", km = 2) ``` -------------------------------- ### Get Size of Row AnnotationFunction Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/size.AnnotationFunction.html Demonstrates how to get the size of a row annotation function. The size function returns the width for row annotations. ```r anno <- ComplexHeatmap:::anno_points(1:10) ComplexHeatmap:::size(anno) ``` -------------------------------- ### Create a Heatmap Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/decorate_title.rd Initializes a heatmap with random data and sets it up for decoration. This is a prerequisite for using `decorate_title`. ```r set.seed(123) Heatmap(matrix(rnorm(100), 10), name = "mat", km = 2) ``` -------------------------------- ### Get Row Order from a HeatmapList with Row Splitting Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/row_order-HeatmapList-method.html Shows how to get the row order when heatmaps have been split by rows (row_km). The output is a list where each element corresponds to a row split. ```r mat = matrix(rnorm(100), 10) ht_list = Heatmap(mat, row_km = 2) + Heatmap(mat) ht_list = draw(ht_list) row_order(ht_list) ``` -------------------------------- ### Multiple Custom Colors Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/anno_horizon.rd This example shows how to apply multiple custom fill colors to positive and negative values, repeating them as needed. ```APIDOC ## anno_horizon with Multiple Custom Colors ### Description Applies multiple custom fill colors to positive and negative values in horizon charts, cycling through the provided colors. ### Arguments - `lt`: A list of time series data. - `which`: Specifies whether to annotate 'row' or 'column'. - `gp`: Graphics parameters, including `pos_fill` and `neg_fill`, which can be vectors of colors. ### Example ```R lt <- lapply(1:20, function(x) cumprod(1 + runif(1000, -x/100, x/100))) - 1 anno <- anno_horizon(lt, which = "row", gp = gpar(pos_fill = rep(c("orange", "red"), each = 10), neg_fill = rep(c("darkgreen", "blue"), each = 10))) draw(anno, test = "horizon chart, col") ``` ``` -------------------------------- ### Get Row Dendrograms from HeatmapList Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/row_dend-HeatmapList-method.rd This snippet demonstrates how to extract row dendrograms from a HeatmapList object. It first creates a HeatmapList with two heatmaps and then draws it. Finally, it calls `row_dend` to get the dendrograms. ```R mat = matrix(rnorm(100), 10) ht_list = Heatmap(mat) + Heatmap(mat) ht_list = draw(ht_list) row_dend(ht_list) ``` -------------------------------- ### Create and Draw anno_mark Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/anno_mark.rd Demonstrates how to create an anno_mark object with specified positions and labels, and then draw it on a heatmap. ```R anno = anno_mark(at = c(1:4, 20, 60, 97:100), labels = month.name[1:10], which = "row") draw(anno, index = 1:100, test = "anno_mark") ``` -------------------------------- ### dim Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/index.html Get the dimension of the Heatmap. ```APIDOC ## dim ### Description Dimension of the Heatmap. ### Method `dim() ` ``` -------------------------------- ### dend_xy Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/index.html Get the coordinates of the Dendrogram. ```APIDOC ## dend_xy() ### Description Coordinates of the Dendrogram. ### Method `dend_xy()` ``` -------------------------------- ### Generate Set Names from Combination Matrix Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/set_name.html This example demonstrates how to create a combination matrix using make_comb_mat and then extract the set names using set_name. Ensure that the input list 'lt' is properly defined. ```R set.seed(123) lt = list(a = sample(letters, 10), b = sample(letters, 15), c = sample(letters, 20)) m = make_comb_mat(lt) set_name(m) ``` -------------------------------- ### nrow Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/index.html Get the number of rows in a heatmap. ```APIDOC ## nrow ### Description Get the number of rows in a heatmap. ### Method `nrow(__)` ``` -------------------------------- ### Density Heatmap with Annotations Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/densityHeatmap.html Demonstrates creating a density heatmap with additional annotations, such as points and categorical data, using HeatmapAnnotation. ```R ha = HeatmapAnnotation(points = anno_points(runif(10)), anno = rep(c("A", "B"), each = 5), col = list(anno = c("A" = "red", "B" = "blue"))) # Note: The actual densityHeatmap call with 'ha' is not provided in the source. ``` -------------------------------- ### ncol Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/index.html Get the number of columns in a heatmap. ```APIDOC ## ncol ### Description Get the number of columns in a heatmap. ### Method `ncol(__)` ``` -------------------------------- ### Draw a basic dendrogram Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/grid.dendrogram.html This example demonstrates how to draw a basic dendrogram. It requires creating a dendrogram object from a matrix and setting up a viewport with appropriate scales before calling grid.dendrogram. ```R m = matrix(rnorm(100), 10) dend = as.dendrogram(hclust(dist(m))) grid.newpage() pushViewport(viewport(xscale = c(0, 10.5), yscale = c(0, dend_heights(dend)), width = 0.9, height = 0.9)) grid.dendrogram(dend) popViewport() ``` -------------------------------- ### get_color_mapping_list Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/index.html Get a List of ColorMapping objects. ```APIDOC ## get_color_mapping_list ### Description Get a List of ColorMapping objects. ### Method `get_color_mapping_list(__)` ``` -------------------------------- ### comb_size Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/index.html Get the sizes of the Combination sets. ```APIDOC ## comb_size() ### Description Sizes of the Combination sets. ### Method `comb_size()` ``` -------------------------------- ### Discrete Color Mapping with map_to_colors Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/map_to_colors-ColorMapping-method.html Demonstrates mapping discrete values to predefined colors using ColorMapping and map_to_colors. Requires a ColorMapping object initialized with specific colors. ```R cm = ColorMapping(colors = c("A" = "red", "B" = "black")) map_to_colors(cm, sample(c("A", "B"), 10, replace = TRUE)) ``` -------------------------------- ### Create Combination Matrix with Binary Matrix Input Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/make_comb_mat.html Shows how to generate a combination matrix using a binary matrix where rows represent elements and columns represent sets. Only binary (0/1) and logical columns are considered. ```R set.seed(123) df = as.data.frame(matrix(sample(0:1, 100, replace = TRUE), ncol = 3)) colnames(df) = c("a", "b", "c") comb_mat = make_comb_mat(df) ``` -------------------------------- ### comb_name Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/index.html Get the names of the Combination sets. ```APIDOC ## comb_name() ### Description Names of the Combination sets. ### Method `comb_name()` ``` -------------------------------- ### comb_degree Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/index.html Get the degrees of the Combination sets. ```APIDOC ## comb_degree() ### Description Degrees of the Combination sets. ### Method `comb_degree()` ``` -------------------------------- ### Creating Legends for Packing Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/packLegend.rd This example demonstrates how to create two different types of legends using the Legend function, one with discrete color fills and another with a color ramp function. These legends can then be packed together. ```R require(circlize) col_fun = colorRamp2(c(0, 0.5, 1), c("blue", "white", "red")) lgd1 = Legend(at = 1:6, legend_gp = gpar(fill = 1:6), title = "legend1") lgd2 = Legend(col_fun = col_fun, title = "legend2", at = c(0, 0.25, 0.5, 0.75, 1)) ``` -------------------------------- ### pindex Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/index.html Get values in a matrix by pair-wise indices. ```APIDOC ## pindex ### Description Get values in a matrix by pair-wise indices. ### Method `pindex()` ``` -------------------------------- ### height Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/index.html Get the height of various heatmap components. ```APIDOC ## height ### Description Get the height of various heatmap components. ### Methods - `height(__)` - `height(__)` - `height(__)` - `height(__)` - `height(__)` - `height(__)` ``` -------------------------------- ### Create and Subset HeatmapAnnotation Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/Extract.HeatmapAnnotation.html Demonstrates creating a HeatmapAnnotation object and subsetting it by rows and columns using different indexing methods. ```R ha = HeatmapAnnotation(foo = 1:10, bar = anno_points(10:1), sth = cbind(1:10, 10:1)) ha[1:5, ] ``` ```R ha[, c("foo", "bar")] ``` ```R ha[, 1:2] ``` ```R ha[1:5, c("foo", "sth")] ``` -------------------------------- ### nobs Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/index.html Get the number of observations for annotation functions or heatmaps. ```APIDOC ## nobs ### Description Get the number of observations for annotation functions or heatmaps. ### Methods - `nobs(__)` - `nobs(__)` - `nobs(__)` ``` -------------------------------- ### Constructing an AnnotationFunction Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/AnnotationFunction.html Demonstrates how to create a basic AnnotationFunction. This is useful for defining custom annotation drawing logic. ```R x = 1:10 anno1 = AnnotationFunction( fun = function(index, k, n) { ``` -------------------------------- ### print Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/index.html Print the comb_mat object. ```APIDOC ## print ### Description Print the comb_mat object. ### Method `print(__)` ``` -------------------------------- ### names Source: https://github.com/jokergoo/complexheatmap.git/blob/master/docs/reference/index.html Get or set names for heatmap annotations or lists. ```APIDOC ## names ### Description Get or set names for heatmap annotations or lists. ### Methods - `names(__)` - `names(__)` - ``[`names<-`(__)`` ```