Skip to contents

Adds a title to the chart legend naming the variable its entries come from. The title renders on whichever legend surface is active – the compact in-plot legend or the panel opened from the chart's legend button – and on exported SVG, PNG and PDF output.

Usage

setLegendTitle(myIO, title = NULL)

Arguments

myIO

an htmlwidget object created by the myIO() function

title

a single character string used as the legend title, or TRUE to derive it from the name of the grouping column supplied as addIoLayer(mapping = list(group = ...)). NULL or FALSE clears the title, which is the default for every chart.

Value

A modified myIO htmlwidget object carrying the legend title.

Details

The title is omitted when suppressLegend() is set. The derived form (title = TRUE) is omitted unless the legend has at least two entries and every entry comes from the same grouping column, so a chart that mixes grouped series with a standalone fitted line stays untitled unless a literal string is supplied.

Examples

df <- data.frame(x = rep(1:5, 2), y = runif(10),
                 Month = rep(c("May", "June"), each = 5))

myIO() |>
  addIoLayer(type = "line", label = "Temp", data = df,
             mapping = list(x_var = "x", y_var = "y", group = "Month")) |>
  setLegendTitle("Month")
# Derive the title from the grouping column name myIO() |> addIoLayer(type = "line", label = "Temp", data = df, mapping = list(x_var = "x", y_var = "y", group = "Month")) |> setLegendTitle(TRUE)