smooth Labels
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 (lmorloess)...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)
)Functions
Defines the format for displaying the value. The format will be applied to the corresponding value specified in the line template.
Use the layer's color for the annotation text.
Sets horizontal anchor positions for each group's annotation label.
Sets vertical anchor positions for each group's annotation label.
Specifies a line template to show in the annotation.
Specifies the text size in the annotation.