Add Labels to Each Cluster in a GC Chart
This function adds labels to each cluster within a GC chart. It provides the option to show or hide the labels and supports customization of label properties. It can automatically pick up group names as labels from the GC_chart object if not provided.
Usage
r
GC_labels(
GC_chart,
label = NULL,
show = TRUE,
cluster = NULL,
itemStyle = list(),
groupStyle = NULL,
style_by = NULL,
...
)Arguments
| Argument | Description |
|---|---|
GC_chart | A GC chart object to which labels will be added. |
label | Character vector, logical, or NULL. Specific labels for the clusters. If NULL and GC_chart has group names, those will be used as labels. |
show | Logical; controls the visibility of labels. Default is TRUE. |
cluster | Numeric or character vector or NULL; specifies which clusters should be labeled. If NULL, labels will be applied to all clusters. Default is NULL. |
itemStyle | List, a list of styles to apply to individual items in the chart. |
groupStyle | Named list of styles by group, applied to the labels of all genes of that group (the group of GC_chart(), or the column given in style_by), e.g. list(tnsA = list(fill = "white")). Takes the same options as itemStyle; the itemStyle of a label takes precedence over the style of its group. |
style_by | Column name or NULL; the column whose values groupStyle is matched against, e.g. the label column to style labels by their text, or "geneTrack" for the track of a gene with GC_cluster()(prevent_gene_overlap = ), e.g. groupStyle = list("2" = list(...)) for the labels of the second track. Default is NULL: the group of GC_chart(). |
... | Additional arguments for further customization of the labels, e.g. adjustLabels: TRUE (default) turns labels that overlap another one, "hide" hides them instead, and FALSE leaves them as they are. A label that would turn out of the plot area, e.g. above its cluster or past the right end, is hidden rather than cut off. Hidden labels come back when there is room for them, e.g. when zoomed in with GC_zoom(). adjustLabels = "spread" puts the labels on one line below the lowest gene, moved apart where they would overlap, with a line from each label to its gene. leaderLine sets the distance from the lowest gene to the labels (length, in pixels, default 20) and the style of the lines, e.g. leaderLine = list(length = 30, stroke = "grey", strokeWidth = 1); leaderLine = FALSE spreads the labels without lines. spreadPosition = "top" puts the spread labels on one line above the highest gene instead (default "bottom"). The lines start at the side of the gene that faces its label, also when a label is dragged to the other side. |
Value
A GC chart object with updated label settings for each specified cluster.
Examples
r
genes_data <- data.frame(
start = c(10, 90, 130, 170, 210),
end = c(40, 120, 160, 200, 240),
name = c('Gene 1', 'Gene 3', 'Gene 4', 'Gene 5', 'Gene 6'),
group = c('A', 'B', 'B', 'A', 'C'),
cluster = c(1, 1, 2, 2, 2)
)
# Add labels to all clusters
GC_chart(genes_data, cluster = "cluster", group = "group", height = "200px") %>%
GC_labels()
# Bold labels for the genes of group A
GC_chart(genes_data, cluster = "cluster", group = "group", height = "200px") %>%
GC_labels(groupStyle = list(A = list(fontWeight = "bold")))
# Add labels and styling
GC_chart(genes_data, cluster = "cluster", group = "group", height = "200px") %>%
GC_labels(
label = "group",
show = TRUE,
x = 0,
y = 50,
dy = "-1.2em",
dx = "0em",
rotate = 0,
adjustLabels = TRUE, # Rotate labels to prevent overlap; "hide" hides them
fontSize = "12px",
fontStyle = "italic",
fill = "black",
fontFamily = "sans-serif",
textAnchor = "middle",
cursor = "default",
)
# Alter style of a specific label
GC_chart(genes_data, cluster = "cluster", group = "group", height = "200px") %>%
GC_labels(label = "group") %>%
GC_labels(
cluster = 1,
itemStyle = list(
list(index = 0, fill = "red", fontSize = "14px", fontWeight = "bold")
)
)