{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "stuffed-springer", "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, "id": "analyzed-lawyer", "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() // Work around Krangl loading old Lets-Plot classes." ] }, { "cell_type": "code", "execution_count": 3, "id": "electronic-tourist", "metadata": {}, "outputs": [], "source": [ "%use krangl" ] }, { "cell_type": "code", "execution_count": 4, "id": "closing-toilet", "metadata": {}, "outputs": [ { "data": { "text/html": [ "manufacturer | model | displ | year | cyl | trans | drv | cty | hwy | fl | class | |
---|---|---|---|---|---|---|---|---|---|---|---|
1 | audi | a4 | 1.8 | 1999 | 4 | auto(l5) | f | 18 | 29 | p | compact |
2 | audi | a4 | 1.8 | 1999 | 4 | manual(m5) | f | 21 | 29 | p | compact |
3 | audi | a4 | 2.0 | 2008 | 4 | manual(m6) | f | 20 | 31 | p | compact |
Shape: 3 x 12. \n", "
" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val df = DataFrame.readCSV(\"https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/data/mpg.csv\")\n", "df.head(3)\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "close-humidity", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val p = letsPlot(df.toMap()) { x = \"cty\"; y = \"hwy\"; color = \"drv\" } +\n", " geomPoint(tooltips = layerTooltips()\n", " .title(\"@manufacturer @model\") \n", " .line(\"@|@class\")\n", " .line(\"@|@year\")) +\n", " labs(\n", " title = \"The plot title\",\n", " subtitle = \"The plot subtitle\",\n", " caption = \"The plot caption\",\n", " color = \"Drive type\"\n", " ) \n", "p" ] }, { "cell_type": "code", "execution_count": 6, "id": "continued-burton", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// Font size and face.\n", "val p1 = p + theme(\n", " title = elementText(size=18),\n", " plotTitle = elementText(face=\"bold\"),\n", " plotCaption = elementText(size=12, face=\"italic\"),\n", " axisText = elementText(size=14, face=\"italic\"),\n", " tooltipText = elementText(size=15)\n", ")\n", "p1" ] }, { "cell_type": "code", "execution_count": 7, "id": "collectible-julian", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// Font family.\n", "p1 + theme(text = elementText(family=\"Times New Roman\"))" ] } ], "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.7.20-dev-1299" } }, "nbformat": 4, "nbformat_minor": 5 }