{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "laughing-rotation", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%useLatestDescriptors\n", "%use lets-plot" ] }, { "cell_type": "code", "execution_count": 2, "id": "33f31202", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Lets-Plot Kotlin API v.4.4.2. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.0.0." ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "LetsPlot.getInfo()" ] }, { "cell_type": "code", "execution_count": 3, "id": "everyday-cheese", "metadata": {}, "outputs": [], "source": [ "val data = mapOf(\n", " \"x\" to listOf(1, 1, 2, 2, 2),\n", " \"y\" to listOf(1, 3, 2, 1, -3),\n", " \"grp\" to listOf(\"a\", \"b\", \"a\", \"b\", \"c\")\n", ")\n", "\n", "val p = letsPlot(data) { x = \"x\"; y = \"y\"; group = \"grp\" } + \n", " geomBar(stat = Stat.identity, color = \"pen\") { fill = \"grp\" } + \n", " scaleFillBrewer(palette = \"Pastel1\") +\n", " theme(axisLineX = elementBlank(), axisTicks = elementBlank()) + \n", " geomHLine(yintercept = 0, color = \"pen\", size = 0.5)\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "exterior-gamma", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "val w = 600\n", "val h = 400\n", "\n", "GGBunch()\n", " .addPlot(p + geomLabel(position = positionStack()) { label = \"y\" } + ggtitle(\"Default\"), 0, 0)\n", " .addPlot(p + geomLabel(position = positionStack(0.0)) { label = \"y\" } + ggtitle(\"vjust = 0.0\"), w, 0)\n", " .addPlot(p + geomLabel(position = positionStack(0.3)) { label = \"y\" } + ggtitle(\"vjust = 0.3\"), 0, h)\n", " .addPlot(p + geomLabel(position = positionStack(0.5)) { label = \"y\" } + ggtitle(\"vjust = 0.5\"), w, h)\n", " .addPlot(p + geomLabel(position = positionStack(0.7)) { label = \"y\" } + ggtitle(\"vjust = 0.7\"), 0, 2*h)\n", " .addPlot(p + geomLabel(position = positionStack(1.0)) { label = \"y\" } + ggtitle(\"vjust = 1.0\"), w, 2*h)\n", " .show()" ] }, { "cell_type": "code", "execution_count": 5, "id": "injured-exchange", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// position = \"fill\"\n", "\n", "letsPlot(data) { x = \"x\"; y = \"y\"; group = \"grp\" } + \n", " geomBar(stat = Stat.identity, position = positionFill(), color = \"pen\") { fill = \"grp\" } + \n", " scaleFillBrewer(palette = \"Pastel1\") +\n", " geomText(position = positionFill(0.5)) { label = \"y\" } +\n", " theme(axisLineX = elementBlank(), axisTicks = elementBlank()) + \n", " geomHLine(yintercept = 0, color = \"pen\", size = 0.5)\n", " \n", " " ] } ], "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 }