{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "fiscal-holly", "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": "worthy-cedar", "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": "received-tablet", "metadata": {}, "outputs": [], "source": [ "%use krangl" ] }, { "cell_type": "code", "execution_count": 4, "id": "weird-republican", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
manufacturermodeldisplyearcyltransdrvctyhwyflclass
1audia41.819994auto(l5)f1829pcompact
2audia41.819994manual(m5)f2129pcompact
3audia42.020084manual(m6)f2031pcompact

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": "accepted-afternoon", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val p = letsPlot(df.toMap()) { x = \"displ\"; y = \"hwy\" } + geomPoint() +\n", " labs(\n", " title = \"Fuel efficiency\\nfor most popular models of car\",\n", " subtitle = \"Period 1999-2008\",\n", " caption = \"MPG Dataset\",\n", " x = \"Engine displacement\\n(litres)\", \n", " y = \"Highway\\nmiles per gallon\"\n", " ) + themeClassic() + theme(plotBackground = elementRect(size=1))\n", "p" ] }, { "cell_type": "code", "execution_count": 6, "id": "posted-newsletter", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// Change margins around plot title, subtitle, caption and axis titles\n", "\n", "p + theme(plotTitle = elementText(margin = margin(t=15)), \n", " plotSubtitle = elementText(margin = margin(b=10)),\n", " plotCaption = elementText(margin = margin(b=15)),\n", " axisTitleX = elementText(margin = margin(t=10)), \n", " axisTitleY = elementText(margin = margin(r=10, l=15)))" ] }, { "cell_type": "code", "execution_count": 7, "id": "median-badge", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// Change margins around axis tick labels\n", "\n", "p + theme(axisTextX = elementText(margin = margin(t=10, b=15)), \n", " axisTextY = elementText(margin = margin(r=10, l=15)))" ] }, { "cell_type": "code", "execution_count": 8, "id": "cutting-justice", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// axis labels at different levels\n", "\n", "val p2 = letsPlot(df.toMap()) { x = \"class\"; y = \"hwy\" } + geomBoxplot()\n", "p2" ] }, { "cell_type": "code", "execution_count": 9, "id": "lightweight-detroit", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p2 + theme(axisTextX = elementText(margin = margin(t=10, b=10)))" ] }, { "cell_type": "code", "execution_count": 10, "id": "alleged-effects", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// with rotation\n", "\n", "val p3 = p2 + ggsize(550, 400)\n", "p3" ] }, { "cell_type": "code", "execution_count": 11, "id": "scheduled-identity", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p3 + theme(axisTextX = elementText(margin = margin(t=10)))" ] } ], "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 }