Skip to content

Set or Update Cluster Labels for a GC Chart ​

This function allows you to set or update the labels for specified clusters within a GC chart. It provides flexibility in terms of the title, visibility, width, position, and other additional customization options.

Usage ​

r
GC_clusterLabel(
  GC_chart,
  title = NULL,
  show = TRUE,
  width = NULL,
  cluster = NULL,
  position = NULL,
  align = NULL,
  wrapLabel = NULL,
  wrapOptions = list(),
  subtitle = NULL,
  subtitleFont = list(),
  spacing = NULL,
  ...
)

Arguments ​

ArgumentDescription
GC_chartA GC chart object.
titleCharacter vector. The title for the cluster label. Default is NULL.
showLogical. Whether to show the cluster label. Default is TRUE.
widthCharacter. The width of the cluster label, which sets the left or right margin of the cluster. Default is NULL: a margin set with GC_grid(), otherwise the width of the theme, otherwise "100px".
clusterNumeric or character vector. Clusters in the GC chart to update. Default is NULL.
positionCharacter. Position of the label, either "left" or "right". Default is NULL: the position of the theme, otherwise "left".
alignCharacter vector. Horizontal alignment of the lines of the label in its margin, "left", "center" or "right", recycled over the clusters. x moves the label from this position, e.g. x = 5 for some space at the left edge. Default is NULL: the alignment of the theme, otherwise "center".
wrapLabelLogical. Indicates whether the label should be wrapped. Default is NULL: as set by the theme, otherwise TRUE.
wrapOptionsList. Specifies the wrapping options. Default is an empty List.
subtitleCharacter vector. A second line below the title, e.g. the species, recycled over the clusters. Default is NULL: no subtitle.
subtitleFontList. Settings for the subtitle font, e.g. list(fontStyle = "italic"). Default is an empty list: 11px, not bold.
spacingNumeric vector. Pixels between the middle of the last line of the title and of the subtitle, recycled over the clusters. The title and subtitle are centred together on the cluster. Default is NULL: as set by the theme, otherwise 1.2 times the mean font size of the title and subtitle (14 for the default 12px and 11px).
...Additional customization arguments for the cluster label, such as 'fontSize', 'fontStyle', 'fontWeight', 'fontFamily', 'cursor', etc.

Value ​

Updated GC chart with new or modified cluster labels.

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)
)

# Set cluster labels
GC_chart(genes_data, cluster ="cluster", group = "group", height = "200px") %>%
GC_clusterLabel(title = unique(genes_data$cluster))

# Set label for a specific cluster
GC_chart(genes_data, cluster ="cluster", group = "group", height = "200px") %>%
GC_clusterLabel(title = "Cluster 1", cluster = 1)

# Add a subtitle below each label
GC_chart(genes_data, cluster ="cluster", group = "group", height = "200px") %>%
  GC_clusterLabel(
    title = c("pQEB1", "pQEB1_inv1"),
    subtitle = c("E. cloacae", "K. oxytoca"),
    subtitleFont = list(fontStyle = "italic"),
    spacing = 14
  )

# Style labels
GC_chart(genes_data, cluster ="cluster", group = "group", height = "200px") %>%
  GC_clusterLabel(
    title = c("Cluster 1", "Cluster 2"),
    width = "100px",
    x = 0,
    y = 0,
    position = "left",
    align = "left", # center / right
    wrapLabel = TRUE,
    wrapOptions = list(
      dyAdjust = 0,
      lineHeightEms = 1.05,
      lineHeightSquishFactor =  1,
      splitOnHyphen =  TRUE,
      centreVertically = TRUE
     ),
    fontSize = "12px",
    fontStyle = "normal",
    fontWeight = "bold",
    fontFamily = "sans-serif",
    cursor = "default"
  )