add_cluster_annotation {seqsetvis} | R Documentation

## add_cluster_annotation

### Description

adds rectangle boxes proportional to cluster sizes of heatmap with optional labels.

### Usage

    add_cluster_annotation(
      cluster_ids,
      p = NULL,
      xleft = 0,
      xright = 1,
      rect_colors = c("black", "gray"),
      text_colors = rev(rect_colors),
      show_labels = TRUE,
      label_angle = 0,
      row_ = "id",
      cluster_ = "cluster_id"
    )

### Arguments

`cluster_ids` | Vector of cluster ids for each item in heatmap. Should be sorted by plot order for heatmap.
`p` | Optionally an existing ggplot to add annotation to.
`xleft` | left side of cluster annotation rectangles. Default is 0.
`xright` | right side of cluster annotation rectangles. Default is 1.
`rect_colors` | colors of rectangle fill, repeat to match number of clusters. Default is c("black", "gray").
`text_colors` | colors of text, repeat to match number of clusters. Default is reverse of rect_colors.
`show_labels` | logical, shoud rectangles be labelled with cluster identity. Default is TRUE.
`label_angle` | angle to add clusters labels at. Default is 0, which is horizontal.
`row_` | variable name mapped to row, likely id or gene name for ngs data. Default is "id" and works with ssvFetch* outputs.
`cluster_` | variable name to use for cluster info. Default is "cluster_id".

### Value

A ggplot with cluster annotations added.

### Examples

    #simplest uses
    add_cluster_annotation(factor(c(rep("A", 3), "B")))
    p = ggplot() + coord_cartesian(xlim = c(0,10))
    add_cluster_annotation(factor(c(rep("A", 3), "B")), p)

    #intended use with ssvSignalHeatmap
    clust_dt = ssvSignalClustering(CTCF_in_10a_profiles_dt, nclust = 3)
    assign_dt = unique(clust_dt[, .(id, cluster_id)])[order(id)]
    p_heat = ssvSignalHeatmap(clust_dt, show_cluster_bars = FALSE)
    add_cluster_annotation(assign_dt$cluster_id, p_heat,
      xleft = -400, xright = -360, rect_colors = rainbow(3), text_colors = "gray")
    p_clusters = add_cluster_annotation(assign_dt$cluster_id,
      rect_colors = rainbow(3), text_colors = "gray")
    #specialized use as plot outside of heatmap
    assemble_heatmap_cluster_bars(plots = list(p_clusters, p_heat), rel_widths = c(1, 3))

[Package seqsetvis version 1.14.4 Index]