Good labels are critical for making your plots accessible to a wider audience. Always ensure the axis and legend labels display the full variable name. Use the plot title and subtitle to explain the main findings. It's common to use the caption to provide information about the data source. tag can be used for adding identification tags to differentiate between multiple plots.
Usage
labs({
"...",
title = waiver({}),
subtitle = waiver({}),
caption = waiver({}),
tag = waiver({}),
alt = waiver({}),
alt_insight = waiver({})
})
xlab({label})
ylab({label})
ggtitle(label, subtitle = waiver({}))
... |
A list of new name-value pairs. The name should be an aesthetic. | |
---|---|---|
title |
The text for the title. | |
subtitle |
The text for the subtitle for the plot which will be displayed below the title. | |
caption |
The text for the caption which will be displayed in the bottom-right of the plot by default. | |
tag |
The text for the tag label which will be displayed at the top-left of the plot by default. | |
alt, alt_insight |
Text used for the generation of alt-text for the plot. See get_alt_text for examples. | |
label |
The title of the respective axis (for xlab() or ylab()) or of the plot (for ggtitle()). |
You can also set axis and legend labels in the individual scales (using the first argument, the name). If you're changing other scale options, this is recommended.
If a plot already has a title, subtitle, caption, etc., and you want to remove it, you can do so by setting the respective argument to NULL. For example, if plot p has a subtitle, then p + labs(subtitle = NULL) will remove the subtitle from the plot.
var cxp = new cxplot("canvas1", mtcars, aes("mpg", "wt", {"color": "cyl"}));
cxp.geom_point();
cxp.labs({"x": "New x label"});
// The plot title appears at the top, with the subtitle
// display in smaller text underneath it
var cxp = new cxplot("canvas2", mtcars, aes("mpg", "wt", {"color": "cyl"}));
cxp.geom_point();
cxp.labs({"title" : "New plot title", "subtitle" : "A subtitle"});
// The caption appears in the bottom-right, and is often used for
// sources, notes or copyright
var cxp = new cxplot("canvas3", mtcars, aes("mpg", "wt", {"color": "cyl"}));
cxp.geom_point();
cxp.labs({"caption": "(based on data from ...)"});