{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This page is available as an executable or viewable Jupyter Notebook:\n", "

\n", "\n", " \n", "\n", "\n", " \n", "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### The `labelFormat` parameter in `geomText()`\n", "\n", "The `labelFormat` parameter specifies template for transforming value of the `label` aesthetic to a string.\n", "\n", "To learn more about formatting templates see: [Formatting](https://github.com/JetBrains/lets-plot-kotlin/blob/master/docs/formats.md)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%useLatestDescriptors\n", "%use lets-plot" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "val df = mapOf(\n", " \"y\" to (0 until 5),\n", " \"z\" to listOf(1.0/3, 12.5/7, -22.5/11, 2.5/7, 31.67/1.77),\n", " \"s\" to listOf(\"one\", \"two\", \"three\", \"four\", \"five\"))\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// Floating point numbers without formatting.\n", "letsPlot(df) + geomText {y = \"y\"; label = \"z\"}" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// Floating point numbers with formatting.\n", "letsPlot(df) + geomText(labelFormat = \".3f\") {y = \"y\"; label = \"z\"; }" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// Floating point numbers as percentage formatting.\n", "letsPlot(df) + geomText(labelFormat = \".1%\") {y = \"y\"; label = \"z\"; }" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// Number format as a part of a string pattern.\n", "letsPlot(df) + geomText(labelFormat = \"Ttl: \\${.2f} (B)\") {y = \"y\"; label = \"z\"; }" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// String pattern without value formatting. \"{}\"\n", "letsPlot(df) + geomText(labelFormat = \"--{}--\") {y = \"y\"; label = \"s\"; }" ] } ], "metadata": { "kernelspec": { "display_name": "Kotlin", "language": "kotlin", "name": "kotlin" }, "language_info": { "codemirror_mode": "text/x-kotlin", "file_extension": ".kt", "mimetype": "text/x-kotlin", "name": "kotlin", "nbconvert_exporter": "", "pygments_lexer": "kotlin", "version": "1.5.20-dev-4184" } }, "nbformat": 4, "nbformat_minor": 2 }