smoothLabels

Configure annotations for geomSmooth() layers.

This class extends layerLabels() and provides additional options for displaying statistics produced by the smooth stat, such as R², adjusted R², and the fitted model equation.

It allows placing a multi-line annotation near the smooth curve and mixing custom text, computed variables (e.g. ..r2..), and a generated equation block. If created without any additional configuration the annotation displays a single line with R².

Supported variables and markers

Use these in line() templates via @..name.. syntax:

  • ..r2.. - R² (coefficient of determination).

  • ..adjr2.. - adjusted R².

  • ..aic.. - Akaike Information Criterion.

  • ..bic.. - Bayesian Information Criterion.

  • ..f.. - F-statistic.

  • ..df1.. - numerator degrees of freedom for the F-test.

  • ..df2.. - denominator degrees of freedom for the F-test.

  • ..p.. - p-value for the overall model F-test.

  • ..method.. - smoothing method label (lm or loess).

  • ..n.. - number of observations used in model fitting.

  • ..cilevel.. - confidence level used for the R² confidence interval.

  • ..cilow.. - lower bound of the R² confidence interval.

  • ..cihigh.. - upper bound of the R² confidence interval.

  • ~eq - fitted equation (use in a line() template to insert the model equation).

Notes

By default, annotation text color is automatically selected for good readability.

Use theme(labelText = elementText(...)) to customize the appearance of annotation text. See also elementText().

Alternatively, the inheritColor() method can be used to make annotation text use the geometry's color aesthetic, overriding both the automatically selected text color and any color specified via theme(labelText = elementText(...)).

Examples

val data = mapOf("x" to listOf(0, 1.5, 1.7, 2), "y" to listOf(0, 1, 1.8, 4))
letsPlot(data) { x = "x"; y = "y" } +
geomPoint() +
geomSmooth(
deg = 2,
labels = smoothLabels()
.line("""\(R^2=\)@..r2..""")
.line("~eq")
.size(16)
)

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
fun eq(lhs: String? = null, rhs: String? = null, format: String? = null, threshold: Number? = null): smoothLabels

Configures the auto-generated equation (~eq marker).

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

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 labelX(vararg positions: String): smoothLabels
fun labelX(positions: List<String>): smoothLabels

Sets horizontal anchor positions for each group's annotation label.

Link copied to clipboard
fun labelY(vararg positions: String): smoothLabels
fun labelY(positions: List<String>): smoothLabels

Sets vertical anchor positions for each group's annotation label.

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

Specifies a line template to show in the annotation.

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

Specifies the text size in the annotation.