{ "cells": [ { "cell_type": "markdown", "id": "dcf8a257", "metadata": {}, "source": [ "# Text Setting for Annotations\n", "\n", "Use the `labelText` parameter in `theme()` to set basic text settings for annotations, using the `elementText()` function with the following parameters: \n", "\n", "- family - font family;\n", "- face - font face (\"plain\", \"italic\", \"bold\", \"bold_italic\");\n", "- size - text size, can also be specified via `layerLabels().size()`;\n", "- color - text color, relevant for pie chart annotations.\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "d8278ae9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%useLatestDescriptors\n", "%use lets-plot\n", "%use dataframe" ] }, { "cell_type": "code", "execution_count": 2, "id": "d17c8cba", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Lets-Plot Kotlin API v.4.6.0. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.2.0." ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "LetsPlot.getInfo()" ] }, { "cell_type": "code", "execution_count": 3, "id": "4d4e61e5", "metadata": {}, "outputs": [ { "data": { "application/kotlindataframe+json": "{\"nrow\":3,\"ncol\":12,\"columns\":[\"untitled\",\"manufacturer\",\"model\",\"displ\",\"year\",\"cyl\",\"trans\",\"drv\",\"cty\",\"hwy\",\"fl\",\"class\"],\"kotlin_dataframe\":[{\"untitled\":1,\"manufacturer\":\"audi\",\"model\":\"a4\",\"displ\":1.8,\"year\":1999,\"cyl\":4,\"trans\":\"auto(l5)\",\"drv\":\"f\",\"cty\":18,\"hwy\":29,\"fl\":\"p\",\"class\":\"compact\"},{\"untitled\":2,\"manufacturer\":\"audi\",\"model\":\"a4\",\"displ\":1.8,\"year\":1999,\"cyl\":4,\"trans\":\"manual(m5)\",\"drv\":\"f\",\"cty\":21,\"hwy\":29,\"fl\":\"p\",\"class\":\"compact\"},{\"untitled\":3,\"manufacturer\":\"audi\",\"model\":\"a4\",\"displ\":2.0,\"year\":2008,\"cyl\":4,\"trans\":\"manual(m6)\",\"drv\":\"f\",\"cty\":20,\"hwy\":31,\"fl\":\"p\",\"class\":\"compact\"}]}", "text/html": [ " \n", " \n", " \n", " \n", " \n", " \n", "
\n", "\n", "

DataFrame: rowsCount = 3, columnsCount = 12

\n", "
untitledmanufacturermodeldisplyearcyltransdrvctyhwyflclass
1audia41.80000019994auto(l5)f1829pcompact
2audia41.80000019994manual(m5)f2129pcompact
3audia42.00000020084manual(m6)f2031pcompact
\n", " \n", " \n", " " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val mpg = DataFrame.readCSV(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv\")\n", "mpg.head(3)" ] }, { "cell_type": "code", "execution_count": 4, "id": "761a1ae7", "metadata": {}, "outputs": [], "source": [ "val labelTextOpts = elementText(family = \"Rockwell\", face = \"bold\", size = 16, color = \"#542788\")" ] }, { "cell_type": "markdown", "id": "e22a2b88", "metadata": {}, "source": [ "#### Configure Text Labels for Bar Plot" ] }, { "cell_type": "code", "execution_count": 5, "id": "03d5b768", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letsPlot(mpg.toMap()) + \n", " geomBar(labels = layerLabels().line(\"@..sumpct..\")) { x = \"class\"; fill = \"class\" } +\n", " theme(labelText = labelTextOpts)" ] }, { "cell_type": "markdown", "id": "17c056a9", "metadata": {}, "source": [ "#### Configure Text Labels for Pie Chart" ] }, { "cell_type": "code", "execution_count": 6, "id": "786bf0aa", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letsPlot(mpg.toMap()) + \n", " geomPie(size = 26, hole = 0.3, labels = layerLabels().line(\"@..proppct..\")) { fill = \"class\" } +\n", " themeVoid() +\n", " theme(labelText = labelTextOpts)" ] } ], "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.8.20" } }, "nbformat": 4, "nbformat_minor": 5 }