{ "cells": [ { "cell_type": "markdown", "id": "enormous-wesley", "metadata": {}, "source": [ "# Pie Chart Stroke and Spacers\n", "\n", "The `stroke` and the `color` aesthetics respectively set **line width** and **line color** of the pie sector arcs. \n", "\n", "The `strokeSide` parameter - \"inner\", \"outer\"(def), \"both\" - specifies where to show the arc.\n", "\n", "By default `stroke` is 0, thus no arc is shown regardless of the value of `strokeSide` parameter.\n", "\n", "Parameters `spacerWidth` and `spacerColor` define lines between sectors.\n", "The default is a narrow segment of the same color as the plot background.\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "minor-highway", "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": "false-girlfriend", "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": "magnetic-blend", "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", " \n", " \n", " " ] }, "execution_count": 3, "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": 4, "id": "framed-detroit", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letsPlot(mpg.toMap()) + \n", " geomPie(size = 20) {\n", " fill = \"class\"\n", " } + \n", " themeVoid()" ] }, { "cell_type": "markdown", "id": "adult-publisher", "metadata": {}, "source": [ "#### 1. `stroke` and `color`" ] }, { "cell_type": "code", "execution_count": 5, "id": "decreased-speaker", "metadata": {}, "outputs": [], "source": [ "val palettes = scaleFillBrewer(palette = \"Pastel2\") + \n", " scaleColorBrewer(palette = \"Set2\")" ] }, { "cell_type": "code", "execution_count": 6, "id": "analyzed-avenue", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letsPlot(mpg.toMap()) + \n", " geomPie(size = 20, stroke = 7) {\n", " fill = \"class\"\n", " color = \"class\"\n", " } +\n", " palettes +\n", " themeVoid()" ] }, { "cell_type": "markdown", "id": "joint-firmware", "metadata": {}, "source": [ "#### 2. `strokeSide`" ] }, { "cell_type": "markdown", "id": "novel-compensation", "metadata": {}, "source": [ "Note: `stroke=7` is added to parameters in order to make arks visible." ] }, { "cell_type": "code", "execution_count": 7, "id": "isolated-democracy", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val p = letsPlot(mpg.toMap()) {\n", " fill = \"class\"\n", " color = \"class\"\n", "} + palettes + themeVoid()\n", "\n", "\n", "gggrid(listOf(\n", " p + geomPie(hole = 0.3, stroke = 7) + ggtitle(\"Outer stroke (Default)\"),\n", " p + geomPie(hole = 0.3, stroke = 7, strokeSide = \"Inner\") + ggtitle(\"Inner stroke\"),\n", " p + geomPie(hole = 0.3, stroke = 7, strokeSide = \"both\") + ggtitle(\"Inner & outer stroke\")\n", ")) + ggsize(1000, 200)" ] }, { "cell_type": "markdown", "id": "durable-growing", "metadata": {}, "source": [ "#### 3. `spacerWidth` and `spacerColor`" ] }, { "cell_type": "markdown", "id": "finished-watson", "metadata": {}, "source": [ "\"Spacer\" is a thin line separating the pie' slices.\\\n", "You can adjust width and color of spacers." ] }, { "cell_type": "code", "execution_count": 8, "id": "canadian-matter", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letsPlot(mpg.toMap()) + \n", " geomPie(size = 20, hole = 0.3, spacerWidth = 4, spacerColor = \"light-gray\") {\n", " fill = \"class\"\n", " } +\n", " themeVoid()" ] }, { "cell_type": "markdown", "id": "velvet-possibility", "metadata": {}, "source": [ "##### 3.1 Spacers with Exploded Sectors \n", "\n", "Spacers are not shown for exploded sectors." ] }, { "cell_type": "code", "execution_count": 9, "id": "floral-captain", "metadata": {}, "outputs": [ { "data": { "application/kotlindataframe+json": "{\"nrow\":2,\"ncol\":13,\"columns\":[\"untitled\",\"manufacturer\",\"model\",\"displ\",\"year\",\"cyl\",\"trans\",\"drv\",\"cty\",\"hwy\",\"fl\",\"class\",\"explode\"],\"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\",\"explode\":0.0},{\"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\",\"explode\":0.0}]}", "text/html": [ " \n", " \n", " \n", " \n", " \n", " \n", "
\n", "\n", "

DataFrame: rowsCount = 2, columnsCount = 13

\n", " \n", " \n", " " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val mpg2 = mpg.add(\"explode\") { if(`class` == \"pickup\") 0.2 else 0.0}\n", "mpg2.head(2)" ] }, { "cell_type": "code", "execution_count": 10, "id": "intelligent-priority", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letsPlot(mpg2.toMap()) + \n", " geomPie(size = 20, hole = 0.3,\n", " stroke = 2, color = \"black\",\n", " strokeSide = \"both\",\n", " spacerWidth = 4, spacerColor = \"light-gray\") {\n", " fill = \"class\"\n", " explode = \"explode\"\n", " } +\n", " themeVoid()" ] } ], "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 }