{ "cells": [ { "cell_type": "markdown", "id": "b62440cf", "metadata": {}, "source": [ "# New Variables `..sumprop..`, `..sumpct..`
in the `count` and `count2d` Statistics\n", "\n", "Computed variables `..sumprop..` and `..sumpct..` take the value of the share of observations at a given location relative to the total number of observations.\n", "\n", "This is in contrast to computed variables `..prop..` and `..proppct..` which take the value of the share of observations belonging to a given group relative to the number of observations at a given location." ] }, { "cell_type": "code", "execution_count": 1, "id": "6a485503", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%useLatestDescriptors\n", "%use lets-plot\n", "%use dataframe" ] }, { "cell_type": "code", "execution_count": 2, "id": "8d4515fd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Lets-Plot Kotlin API v.4.6.0. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.2.0." ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "LetsPlot.getInfo()" ] }, { "cell_type": "code", "execution_count": 3, "id": "ef162c3b", "metadata": {}, "outputs": [], "source": [ "val data = mapOf(\n", " \"x\" to listOf('a', 'a', 'a', 'a', 'b', 'b'),\n", " \"group\" to listOf('A', 'A', 'A', 'B', 'A', 'B')\n", ")" ] }, { "cell_type": "code", "execution_count": 4, "id": "40242443", "metadata": {}, "outputs": [], "source": [ "val tooltipOptions = layerTooltips(\"..sumprop..\", \"..sumpct..\", \"..prop..\", \"..proppct..\")" ] }, { "cell_type": "markdown", "id": "5a06dd44", "metadata": {}, "source": [ "#### 1. Use New `..sumprop..` and `..sumpct..` for Plots without Grouping \n", "\n", "> Note: compare vaues shown in the tooltip." ] }, { "cell_type": "code", "execution_count": 5, "id": "4dda7d88", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letsPlot(data) { x = \"x\" } + \n", " geomBar(tooltips = tooltipOptions, labels = layerLabels().line(\"@..sumprop.. (@..sumpct..)\"))" ] }, { "cell_type": "markdown", "id": "8e7fb2fa", "metadata": {}, "source": [ "#### 2. However `..prop..`, `..proppct..` Better Suit for Grouped Plots \n", "\n", "> Note: again, compare vaues shown in the tooltip." ] }, { "cell_type": "code", "execution_count": 6, "id": "e7f797e9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letsPlot(data) { x = \"x\"; fill = \"group\" } + \n", " geomBar(tooltips = tooltipOptions, labels = layerLabels().line(\"@..prop.. (@..proppct..)\"))" ] }, { "cell_type": "markdown", "id": "21ae080c", "metadata": {}, "source": [ "#### 3. The `count2d` Stat Works Similarly" ] }, { "cell_type": "code", "execution_count": 7, "id": "f771ba20", "metadata": {}, "outputs": [ { "data": { "application/kotlindataframe+json": "{\"nrow\":3,\"ncol\":12,\"columns\":[\"untitled\",\"manufacturer\",\"model\",\"displ\",\"year\",\"cyl\",\"trans\",\"drv\",\"cty\",\"hwy\",\"fl\",\"class\"],\"kotlin_dataframe\":[{\"untitled\":1,\"manufacturer\":\"audi\",\"model\":\"a4\",\"displ\":1.8,\"year\":1999,\"cyl\":4,\"trans\":\"auto(l5)\",\"drv\":\"f\",\"cty\":18,\"hwy\":29,\"fl\":\"p\",\"class\":\"compact\"},{\"untitled\":2,\"manufacturer\":\"audi\",\"model\":\"a4\",\"displ\":1.8,\"year\":1999,\"cyl\":4,\"trans\":\"manual(m5)\",\"drv\":\"f\",\"cty\":21,\"hwy\":29,\"fl\":\"p\",\"class\":\"compact\"},{\"untitled\":3,\"manufacturer\":\"audi\",\"model\":\"a4\",\"displ\":2.0,\"year\":2008,\"cyl\":4,\"trans\":\"manual(m6)\",\"drv\":\"f\",\"cty\":20,\"hwy\":31,\"fl\":\"p\",\"class\":\"compact\"}]}", "text/html": [ " \n", " \n", " \n", " \n", " \n", " \n", "
\n", "\n", "

DataFrame: rowsCount = 3, columnsCount = 12

\n", "
untitledmanufacturermodeldisplyearcyltransdrvctyhwyflclass
1audia41.80000019994auto(l5)f1829pcompact
2audia41.80000019994manual(m5)f2129pcompact
3audia42.00000020084manual(m6)f2031pcompact
\n", " \n", " \n", " " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val mpg = DataFrame.readCSV(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv\")\n", "mpg.head(3)" ] }, { "cell_type": "code", "execution_count": 8, "id": "4f233ccf", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letsPlot(mpg.toMap()) { x = \"drv\"; y = asDiscrete(\"year\") } +\n", " geomPie(tooltips = tooltipOptions) { fill = \"class\"; size = \"..sum..\" } +\n", " scaleSize(guide = \"none\")" ] } ], "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 }