{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Formatting labels on plots.\n", "\n", "In Lets-Plot you can apply a formatting to:\n", "\n", "- axis break values.\n", "- labels displayed by `geomText()`.\n", "- tooltip text.\n", "- facet labels.\n", "\n", "Using format string you can format values of numeric and date-time types.\n", "\n", "In addition, you can use a *string template*.\n", "\n", "In *string template* the value's format string is surrounded by curly braces: `\"... {.2f} ...\"`.\n", "\n", "An empty placeholder `{}` is also allowed. In this case a default string representation will be shown. This is also applicable to categorical values.\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\n", "//%use krangl" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Lets-Plot Kotlin API v.4.1.1. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.2.5.1." ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "LetsPlot.getInfo() // This prevents Krangl from loading an obsolete version of Lets-Plot classes." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### The US Unemployment Rates 2000-2016" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "%use krangl" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "var economics = DataFrame.readCSV(\"https://vincentarelbundock.github.io/Rdatasets/csv/ggplot2/economics.csv\")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "date | pce | pop | psavert | uempmed | unemploy | |
---|---|---|---|---|---|---|
1 | Sat Jul 01 00:00:00 EDT 1967 | 506.7 | 198712 | 12.6 | 4.5 | 2944 |
2 | Tue Aug 01 00:00:00 EDT 1967 | 509.8 | 198911 | 12.6 | 4.7 | 2945 |
3 | Fri Sep 01 00:00:00 EDT 1967 | 515.6 | 199113 | 11.9 | 4.6 | 2958 |
Shape: 3 x 7. \n", "
" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import java.text.SimpleDateFormat\n", "val yyyyMmDd = SimpleDateFormat(\"yyyy-MM-dd\")\n", "economics = economics.addColumn(\"date\") { it[\"date\"].map