{ "cells": [ { "cell_type": "markdown", "id": "12813172", "metadata": {}, "source": [ "# Multiple Lines for Legend Text\n", "\n", "The 'newline' character (`\\n`) now works as 'line break' in the legend text." ] }, { "cell_type": "code", "execution_count": 1, "id": "05483082", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%useLatestDescriptors\n", "%use lets-plot" ] }, { "cell_type": "code", "execution_count": 2, "id": "391c711f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Lets-Plot Kotlin API v.4.4.0. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.3.2.0." ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "LetsPlot.getInfo()" ] }, { "cell_type": "code", "execution_count": 3, "id": "7ccdfeaf", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%use dataframe" ] }, { "cell_type": "code", "execution_count": 4, "id": "82d9327e", "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", " \n", " \n", " " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val df = DataFrame.readCSV(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv\")\n", "df.head(3)" ] }, { "cell_type": "code", "execution_count": 5, "id": "d2621651", "metadata": {}, "outputs": [], "source": [ "val p = letsPlot(df.toMap()) { x = \"displ\"; y = \"hwy\" } + geomPoint(size = 5) { color = \"cty\"; shape = \"drv\" }" ] }, { "cell_type": "markdown", "id": "3011d27b", "metadata": {}, "source": [ "#### Legend labels with 'line breaks'" ] }, { "cell_type": "code", "execution_count": 6, "id": "08d4b211", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val ctyBreaks = listOf(35, 30, 25, 20, 15, 10)\n", "val ctyLabels = ctyBreaks.map { \"$it\\n(mpg)\" }\n", "\n", "val drvBreaks = listOf(\"f\", \"r\", \"4\")\n", "val drvLabels = listOf(\"Front-wheel\\ndrive\", \"Rear \\n wheel \\n drive\", \"4 wheel drive\")\n", "\n", "p + scaleColorContinuous(breaks = ctyBreaks, labels = ctyLabels) +\n", " scaleShape(breaks = drvBreaks, labels = drvLabels) +\n", " theme().legendPositionBottom()" ] } ], "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 }