Skip to main content

Define different titles with TITLE

Note

This page is about the VISUALISE usage of the TITLE clause. For the TABULATE usage, see this page.

The TITLE clause is one of the simpler clauses in ggsql and allows you to override the default naming of axes and legends, as well as adding titles to the plot.

Clause syntax

The TITLE clause takes one or more labeling settings.

TITLE <aesthetic/title> => <string>, ...

If an aesthetic is given, then the title will be used for the relevant axis or legend, e.g. x => 'my x-axis' will label the x axis, whereas fill => 'Species' will label the legend for fill (if any).

There are a few additional labels beside the aesthetics that govern the different titles of the plot and can be given instead of an aesthetic name:

  • main: The main title of the plot
  • sub: An additional, often longer and more descriptive, title beneath the main title
  • caption: A string placed below the plot, often used to add additional information about the data source etc. Supported by every writer except Vega-Lite, which has no equivalent.

Rich text

Every writer except Vega-Lite interprets the strings you provide here as markdown, so TITLE main => 'Sales in **2024**' renders the year in bold. This applies to the plot title, subtitle and caption, to the axis and legend titles, and to break labels (axis tick labels and legend keys). The Vega-Lite writer has no rich-text support at all and draws every label exactly as given.

The recognised markdown is the same as for the text layer.

There is currently no way to turn this off for labels — the parse setting only covers text layers.

Automatic labelling logic

Axes and legends get an automatic label from the mapping. The logic is as follows:

  1. Start from the global mapping and then go through the layer mappings as they appear.
  2. Collect mappings for each aesthetic in the order they appear
  3. For each aesthetic determine the label based on the following priority:
    1. An explicitly provided one with TITLE
    2. The name of the first appearing column mapping
    3. The name of the aesthetic

This means that constants mapped to an aesthetic don’t contribute to the derived label, only data columns, and if all else fails the name of the aesthetic will be used.