Skip to contents

This function configures the legend for a gene chart. It allows toggling the legend's visibility, setting a background color, and assigning custom labels for the legend entries. The function can also handle additional customizations through various options.

Usage

GC_legend(
  GC_chart,
  group = NULL,
  show = TRUE,
  backgroundColor = "#0000",
  order = list(),
  position = "bottom",
  style = list(),
  legendOptions = list(),
  legendTextOptions = list(),
  ...
)

Arguments

GC_chart

The gene chart object to be modified.

group

Optional; character or NULL, specifies the groups to include in the legend. If NULL, groups are taken from the 'group' attribute of the 'GC_chart' object.

show

Logical, specifies whether to display the legend.

backgroundColor

String, the background color of the legend.

order

Optional; list, specifies the order of the legend labels.

position

Character. Position of the legend, either "top" or "bottom". Default is "bottom".

style

A list of CSS styles to be applied to the chart container. Each element of the list should be a valid CSS property-value pair. For example, list(backgroundColor = "white", border = "2px solid black"). Default is an empty list.

legendOptions

List, additional options for the legend.

legendTextOptions

List, additional text options for the legend.

...

Additional arguments to be passed to the legend configuration.

Value

Returns the modified gene chart object with the legend configured.

Examples

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('A', 'A', 'A', 'B', 'B')
)

# Customize legend
GC_chart(genes_data, cluster = "cluster", group = "group", height = "200px") %>%
  GC_legend(
    position = "top", #bottom
    orientation = "horizontal", #vertical
    x = 0,
    y = 0,
    width = NULL, # 100 / "100px" / 50%
    adjustHeight = TRUE,
    backgroundColor = "#0000",
    order = list(),
    positions = "bottom",
    style = list(
      backgroundColor = "#0000"
      # Any other CSS styles
    ),
    legendOptions = list(
      cursor = "pointer",
      colorScheme = NULL,
      customColors = NULL # c("red", "green", "orange")
      # Additional styles
    ),
    legendTextOptions = list(
      cursor = "pointer",
      textAnchor = "start",
      dy = ".35em",
      fontSize = "12px",
      fontFamily = "sans-serif",
      fill = "black"
      # Additional styles
    )
  )