{ "cells": [ { "cell_type": "markdown", "id": "d690b2ab-7cc3-45d6-b4d8-e62ef2f5ea7d", "metadata": {}, "source": [ "# `statSummaryBin()`" ] }, { "cell_type": "code", "execution_count": 1, "id": "c33b6a15-6313-4624-b9e4-c4d1cc405dc0", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "DataFrame: rowsCount = 5, columnsCount = 5
\n", " \n", " \n", " " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "var irisDf = DataFrame.readCSV(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/iris.csv\")\n", "val irisData = irisDf.toMap()\n", "irisDf.head()" ] }, { "cell_type": "markdown", "id": "bf8e3206-d8f7-4d70-91df-d9f330438851", "metadata": {}, "source": [ "#### 1. The `geom` Parameter" ] }, { "cell_type": "code", "execution_count": 3, "id": "864fefe8-3742-4736-8b7e-58fc49e79ba8", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letsPlot(irisData) { x = \"petal_length\"; y = \"sepal_length\" } +\n", " statSummaryBin(geom = Geom.crossbar(width = 1.0), binWidth = 0.5) +\n", " geomPoint(shape = 21, stroke=0.5)" ] }, { "cell_type": "markdown", "id": "e678473b-0cc3-44cf-8aa1-c03dc1ec195f", "metadata": {}, "source": [ "#### 2. `fn`, `fnMin`, `fnMax` Parameters" ] }, { "cell_type": "code", "execution_count": 4, "id": "73fa5c35-8907-4c45-9652-3088072cb7de", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letsPlot(irisData) { x = \"petal_length\"; y = \"sepal_length\" } +\n", " statSummaryBin(geom = Geom.crossbar(width = 1.0), binWidth = 0.5,\n", " fn = \"mq\", fnMin = \"lq\", fnMax = \"uq\") +\n", " geomPoint(shape = 21, stroke=0.5)" ] }, { "cell_type": "markdown", "id": "581f9dab-f576-48d8-bba4-5f91b2c10ba2", "metadata": {}, "source": [ "#### 3. The `quantiles` Parameter" ] }, { "cell_type": "code", "execution_count": 5, "id": "2497b1ca-e239-4a6c-b665-a4d7a0ee0e9a", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letsPlot(irisData) { x = \"petal_length\"; y = \"sepal_length\" } +\n", " statSummaryBin(geom = Geom.crossbar(width = 1.0), binWidth = 0.5,\n", " fn = \"mq\", fnMin = \"lq\", fnMax = \"uq\",\n", " quantiles = listOf(0.05, 0.5, 0.95)) +\n", " geomPoint(shape = 21, stroke=0.5)" ] }, { "cell_type": "markdown", "id": "90d78d62-08a1-4da0-aa9c-b3c6a38a0db5", "metadata": {}, "source": [ "#### 4. `center` and `boundary` Parameters" ] }, { "cell_type": "code", "execution_count": 6, "id": "057b5436-2636-4d1a-92eb-f35ab915ed07", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fun getPlot(center: Double? = null, boundary: Double? = null): org.jetbrains.letsPlot.intern.Plot {\n", " return letsPlot(irisData) { x = \"petal_length\"; y = \"sepal_length\" } +\n", " statSummaryBin(geom = Geom.crossbar(width = 1.0), binWidth = 0.5,\n", " center = center, boundary = boundary) +\n", " geomPoint(shape = 21, stroke=0.5) +\n", " ggtitle(\"center = $center; boundary = $boundary\")\n", "}\n", "\n", "gggrid(listOf(\n", " getPlot(),\n", " getPlot(center = 1.0),\n", " getPlot(boundary = 1.0)\n", "), ncol = 2)" ] }, { "cell_type": "markdown", "id": "5230abf6-fade-415e-a2b6-598005050bee", "metadata": {}, "source": [ "#### 5. Custom Calculations in Aesthetics" ] }, { "cell_type": "code", "execution_count": 7, "id": "c21ee79e-979a-42ca-a7d2-37a862c5edac", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letsPlot(irisData) { x = \"petal_length\"; y = \"sepal_length\" } +\n", " statSummaryBin(geom = Geom.crossbar(width = 1.0),\n", " fn = \"median\", binWidth = 0.5, color = \"white\")\n", " { fill = \"..count..\" } +\n", " geomPoint(shape = 21, stroke=0.5)" ] } ], "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 }