labelFormat
parameter in geomText()
¶The labelFormat
parameter specifies template for transforming value of the label
aesthetic to a string.
To learn more about formatting templates see: Formatting.
%useLatestDescriptors
%use lets-plot
val df = mapOf<String, Any>(
"y" to (0 until 5),
"z" to listOf(1.0/3, 12.5/7, -22.5/11, 2.5/7, 31.67/1.77),
"s" to listOf("one", "two", "three", "four", "five"))
// Floating point numbers without formatting.
letsPlot(df) + geomText {y = "y"; label = "z"}
// Floating point numbers with formatting.
letsPlot(df) + geomText(labelFormat = ".3f") {y = "y"; label = "z"; }
// Floating point numbers as percentage formatting.
letsPlot(df) + geomText(labelFormat = ".1%") {y = "y"; label = "z"; }
// Number format as a part of a string pattern.
letsPlot(df) + geomText(labelFormat = "Ttl: \${.2f} (B)") {y = "y"; label = "z"; }
// String pattern without value formatting. "{}"
letsPlot(df) + geomText(labelFormat = "--{}--") {y = "y"; label = "s"; }