layerLabels

class layerLabels(variables: String)

Configure annotations for geometry layers.

Annotations are currently supported for bar, pie, and crossbar geometry layers. This class provides methods to customize the appearance and content of text labels displayed on these geometries.

Notes

By default, annotation text color is automatically selected for optimal contrast: white text appears on darker filled geometries, and black text appears on lighter filled geometries.

The text color can be manually specified using: `theme(labelText=elementText(color=...))`

Alternatively, the `inheritColor()` method can be used to override both automatic and manual color settings, making the annotation text use the geometry's `color` aesthetic instead.

Examples

val data = mapOf("name" to listOf("a", "b", "c", "d", "b"), "value" to listOf(40, 90, 10, 50, 20))
letsPlot(data) +
geomPie(
size = 15, hole = 0.2,
labels = layerLabels("..proppct..").format("..proppct..", "{.1f}%").size(15)
) { fill = asDiscrete("name", orderBy = "..count.."); weight = "value" }

Parameters

variables

Variable names to place in the annotation with default formatting. Useful for specifying the annotation content quickly, instead of configuring it via the line() method.

Constructors

Link copied to clipboard
constructor(vararg variables: String)

Functions

Link copied to clipboard
fun format(field: String, format: String): layerLabels

Defines the format for displaying the value. The format will be applied to the corresponding value specified in the line template.

Link copied to clipboard

Use the layer's color for the annotation text.

Link copied to clipboard
fun line(template: String): layerLabels

Specifies the string template to use in the annotation.

Link copied to clipboard
fun size(value: Number): layerLabels

Specifies a text size in the annotation.