{ "cells": [ { "cell_type": "markdown", "id": "e470874e-9f02-4a7b-9132-bd91bf4a00fe", "metadata": {}, "source": [ "# Interval geometries\n", "\n", "With own stat:\n", "\n", "- `geom_boxplot()`\n", "- `geom_violin()`\n", "- `geom_ydotplot()`\n", "\n", "Without stat:\n", "\n", "- `geom_errorbar()`\n", "- `geom_crossbar()`\n", "- `geom_linerange()`\n", "- `geom_pointrange()`\n", "\n", "Without geom:\n", "\n", "- `stat_summary()`" ] }, { "cell_type": "code", "execution_count": 1, "id": "33c5e987-ab9d-4062-a2e7-7e02ba22fec4", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "5249aa23-66a5-442e-9f01-d44a820432b1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "ba48e8b5-64c8-4a60-923f-8b7b10e7d8eb", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(234, 12)\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Unnamed: 0manufacturermodeldisplyearcyltransdrvctyhwyflclass
01audia41.819994auto(l5)f1829pcompact
12audia41.819994manual(m5)f2129pcompact
23audia42.020084manual(m6)f2031pcompact
34audia42.020084auto(av)f2130pcompact
45audia42.819996auto(l5)f1626pcompact
\n", "
" ], "text/plain": [ " Unnamed: 0 manufacturer model displ year cyl trans drv cty hwy \\\n", "0 1 audi a4 1.8 1999 4 auto(l5) f 18 29 \n", "1 2 audi a4 1.8 1999 4 manual(m5) f 21 29 \n", "2 3 audi a4 2.0 2008 4 manual(m6) f 20 31 \n", "3 4 audi a4 2.0 2008 4 auto(av) f 21 30 \n", "4 5 audi a4 2.8 1999 6 auto(l5) f 16 26 \n", "\n", " fl class \n", "0 p compact \n", "1 p compact \n", "2 p compact \n", "3 p compact \n", "4 p compact " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.read_csv(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/refs/heads/master/data/mpg.csv\")\n", "print(df.shape)\n", "df.head()" ] }, { "cell_type": "markdown", "id": "517393e7-a288-4015-9573-5af67a9fa390", "metadata": {}, "source": [ "## [Issue #1319](https://github.com/JetBrains/lets-plot/issues/1319) - `geom_boxplot`: unable to draw a y-oriented plot with `stat='identity'`" ] }, { "cell_type": "code", "execution_count": 4, "id": "441219a4-2cde-4c23-a333-1cbecdae5129", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def get_issue1319_data():\n", " return {\n", " 'cat': ['a', 'b'],\n", " 'min': [-4, -2],\n", " 'lower': [-2, -1],\n", " 'middle': [0, 0],\n", " 'upper': [2, 1],\n", " 'max': [4, 2]\n", " }\n", "\n", "ggplot(get_issue1319_data()) + \\\n", " geom_boxplot(aes(y='cat', xmin='min', xlower='lower', xmiddle='middle', xupper='upper', xmax='max'), stat='identity') + \\\n", " ggtitle(\"EXPECTED: correct plot\")" ] }, { "cell_type": "markdown", "id": "b922d645-3d00-48de-ada2-51cf124b799d", "metadata": {}, "source": [ "## Orientation tests" ] }, { "cell_type": "code", "execution_count": 5, "id": "cc857ce3-341a-4091-8b2e-354f15779eb5", "metadata": {}, "outputs": [], "source": [ "def aes_name(col_name, swap):\n", " custom_names = {\"lower\": \"xlower\", \"xlower\": \"lower\",\n", " \"upper\": \"xupper\", \"xupper\": \"upper\",\n", " \"middle\": \"xmiddle\", \"xmiddle\": \"middle\"}\n", " if not swap:\n", " return col_name\n", " if col_name in custom_names:\n", " return custom_names[col_name]\n", " elif \"x\" == col_name[0]:\n", " return \"y\" + col_name[1:]\n", " elif \"y\" == col_name[0]:\n", " return \"x\" + col_name[1:]\n", " else:\n", " return col_name\n", "\n", "def get_oriented_plot(geom, data, *, stat=None, swap=False, orientation=None, flip=False, expected_text=None, mapping={}, parameters={}):\n", " geom_name = geom.__name__\n", " generated_parameters = {}\n", " generated_mapping = {aes_name(col_name, swap): col_name for col_name, col_values in data.items()}\n", " if 'color' in generated_mapping:\n", " generated_mapping['fill'] = generated_mapping['color']\n", " generated_parameters['alpha'] = .75\n", " final_mapping = {**generated_mapping, **mapping}\n", " if geom_name != \"geom_ydotplot\" and 'fill' in final_mapping:\n", " generated_parameters['position'] = position_dodge(width=.95)\n", " if stat is not None:\n", " generated_parameters['stat'] = stat\n", " if orientation is not None:\n", " generated_parameters['orientation'] = orientation\n", " final_parameters = {**generated_parameters, **parameters}\n", " if expected_text is None:\n", " if swap and orientation != 'y':\n", " if geom_name in ['geom_errorbar', 'geom_crossbar', 'geom_linerange', 'geom_pointrange']:\n", " expected_text = \"correct plot\"\n", " else:\n", " expected_text = \"works if it can\"\n", " elif not swap and orientation == 'y':\n", " expected_text = \"incorrect plot\"\n", " else:\n", " expected_text = \"correct plot\"\n", " p = ggplot(data) + \\\n", " geom(aes(**final_mapping), **final_parameters) + \\\n", " ggtitle(\"{geom}():{swap}\\nstat={stat}, orientation={o}{flip}{expected}\".format(\n", " geom=geom_name,\n", " stat=stat,\n", " o=orientation,\n", " swap=\"\\nmapping is inverse\" if swap else \"\",\n", " flip=\"\\ncoordinates are flipped\" if flip else \"\",\n", " expected=\"\\nEXPECTED: {0}\".format(expected_text),\n", " ))\n", " if flip:\n", " p += coord_flip()\n", " return p" ] }, { "cell_type": "markdown", "id": "58845a14-d045-4558-8099-e7174087370b", "metadata": {}, "source": [ "### Boxplot" ] }, { "cell_type": "markdown", "id": "7651c325-9aba-4e12-8344-dee89e5471d6", "metadata": {}, "source": [ "#### Default stat" ] }, { "cell_type": "code", "execution_count": 6, "id": "ba0656d6-b317-4be5-a461-b1e2a063e86b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# no x\n", "\n", "box_data1 = {\n", " 'y': [55, 53, 49, 47, 56, 54, 50, 48],\n", " 'color': ['p'] * 4 + ['q'] * 4,\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_boxplot, box_data1),\n", " get_oriented_plot(geom_boxplot, box_data1, swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_data1, swap=True),\n", " get_oriented_plot(geom_boxplot, box_data1, flip=True),\n", " get_oriented_plot(geom_boxplot, box_data1, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_data1, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 7, "id": "f2fb572e-07e5-4324-b9c0-20968e07e802", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# no x\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_boxplot, box_data1, orientation='y')" ] }, { "cell_type": "code", "execution_count": 8, "id": "e4132360-855c-47de-8fec-d85f992b667b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, one value for each color\n", "\n", "box_data2 = {\n", " 'x': ['a'] * 8,\n", " 'y': [55, 53, 49, 47, 56, 54, 50, 48],\n", " 'color': ['p'] * 4 + ['q'] * 4,\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_boxplot, box_data2),\n", " get_oriented_plot(geom_boxplot, box_data2, swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_data2, swap=True),\n", " get_oriented_plot(geom_boxplot, box_data2, flip=True),\n", " get_oriented_plot(geom_boxplot, box_data2, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_data2, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 9, "id": "77280cb1-2e41-4bce-ab7f-448d7a841546", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, one value for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_boxplot, box_data2, orientation='y')" ] }, { "cell_type": "code", "execution_count": 10, "id": "9b6f22b2-a858-4e2e-b804-942c0967e173", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, few values for each color\n", "\n", "box_data3 = {\n", " 'x': ['a'] * 8 + ['b'] * 4,\n", " 'y': [-55, -53, -49, -47, -56, -54, -50, -48,\n", " -50, -49, -47, -46],\n", " 'color': ['p'] * 4 + ['q'] * 4 + ['p'] * 4,\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_boxplot, box_data3),\n", " get_oriented_plot(geom_boxplot, box_data3, swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_data3, swap=True),\n", " get_oriented_plot(geom_boxplot, box_data3, flip=True),\n", " get_oriented_plot(geom_boxplot, box_data3, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_data3, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 11, "id": "29157cac-2b3d-446d-be58-2f4ad10f586d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, few values for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_boxplot, box_data3, orientation='y')" ] }, { "cell_type": "code", "execution_count": 12, "id": "d58b60ff-e268-4756-a153-ec216b1110b4", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, one value for each color\n", "\n", "box_data4 = {\n", " 'x': [50] * 8,\n", " 'y': [-102, -101, -99, -98, -103, -102, -100, -99],\n", " 'color': ['p'] * 4 + ['q'] * 4,\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_boxplot, box_data4),\n", " get_oriented_plot(geom_boxplot, box_data4, swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_data4, swap=True),\n", " get_oriented_plot(geom_boxplot, box_data4, flip=True),\n", " get_oriented_plot(geom_boxplot, box_data4, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_data4, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 13, "id": "cedaa7b5-bb48-4ae3-b192-c5f0e47b6d13", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, one value for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_boxplot, box_data4, orientation='y')" ] }, { "cell_type": "code", "execution_count": 14, "id": "28ad95eb-0734-4ae9-9c3f-a818939c859b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, few values for each color\n", "\n", "box_data5 = {\n", " 'x': [95] * 8 + [105] * 4,\n", " 'y': [55, 53, 49, 47, 56, 54, 50, 48,\n", " 50, 49, 47, 46],\n", " 'color': ['p'] * 4 + ['q'] * 4 + ['p'] * 4,\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_boxplot, box_data5),\n", " get_oriented_plot(geom_boxplot, box_data5, swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_data5, swap=True),\n", " get_oriented_plot(geom_boxplot, box_data5, flip=True),\n", " get_oriented_plot(geom_boxplot, box_data5, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_data5, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 15, "id": "d686c682-617a-4c4d-a58b-51eb8b7b774c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, few values for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_boxplot, box_data5, orientation='y')" ] }, { "cell_type": "markdown", "id": "a227e9ea-d81c-4ab3-b252-be2c37e277b6", "metadata": {}, "source": [ "#### `stat='identity'`" ] }, { "cell_type": "code", "execution_count": 16, "id": "6c6d4dfc-5e17-4f66-978e-605ab26f0eef", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# no x\n", "\n", "box_identity_data1 = {\n", " 'ymin': [19, 20],\n", " 'lower': [20, 21],\n", " 'middle': [21, 22],\n", " 'upper': [22, 23],\n", " 'ymax': [23, 24],\n", " 'color': ['p', 'q'],\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_boxplot, box_identity_data1, stat='identity'),\n", " get_oriented_plot(geom_boxplot, box_identity_data1, stat='identity', swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_identity_data1, stat='identity', swap=True),\n", " get_oriented_plot(geom_boxplot, box_identity_data1, stat='identity', flip=True),\n", " get_oriented_plot(geom_boxplot, box_identity_data1, stat='identity', flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_identity_data1, stat='identity', flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 17, "id": "9170f6d9-29b4-418f-8726-b9936339220d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# no x\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_boxplot, box_identity_data1, stat='identity', orientation='y')" ] }, { "cell_type": "code", "execution_count": 18, "id": "49db8f56-3769-4ac0-8541-c514afbc8021", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, one value for each color\n", "\n", "box_identity_data2 = {\n", " 'x': ['a', 'a'],\n", " 'ymin': [19, 20],\n", " 'lower': [20, 21],\n", " 'middle': [21, 22],\n", " 'upper': [22, 23],\n", " 'ymax': [23, 24],\n", " 'color': ['p', 'q'],\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_boxplot, box_identity_data2, stat='identity'),\n", " get_oriented_plot(geom_boxplot, box_identity_data2, stat='identity', swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_identity_data2, stat='identity', swap=True),\n", " get_oriented_plot(geom_boxplot, box_identity_data2, stat='identity', flip=True),\n", " get_oriented_plot(geom_boxplot, box_identity_data2, stat='identity', flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_identity_data2, stat='identity', flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 19, "id": "c0798795-e3e1-4a94-89fd-aa5c7fa8c7e2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, one value for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_boxplot, box_identity_data2, stat='identity', orientation='y')" ] }, { "cell_type": "code", "execution_count": 20, "id": "4ecacbb1-5351-43af-a311-f70e34fb4d0b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, few values for each color\n", "\n", "box_identity_data3 = {\n", " 'x': ['a', 'a', 'b'],\n", " 'ymin': [-23, -24, -21],\n", " 'lower': [-22, -23, -20],\n", " 'middle': [-21, -22, -19],\n", " 'upper': [-20, -21, -18],\n", " 'ymax': [-19, -20, -17],\n", " 'color': ['p', 'q', 'p'],\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_boxplot, box_identity_data3, stat='identity'),\n", " get_oriented_plot(geom_boxplot, box_identity_data3, stat='identity', swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_identity_data3, stat='identity', swap=True),\n", " get_oriented_plot(geom_boxplot, box_identity_data3, stat='identity', flip=True),\n", " get_oriented_plot(geom_boxplot, box_identity_data3, stat='identity', flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_identity_data3, stat='identity', flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 21, "id": "8ef689cf-244c-41e3-888b-22d7bf131b81", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, few values for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_boxplot, box_identity_data3, stat='identity', orientation='y')" ] }, { "cell_type": "code", "execution_count": 22, "id": "46b572cd-d65f-4243-833b-5483b5b6dff4", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, one value for each color\n", "\n", "box_identity_data4 = {\n", " 'x': [100, 100],\n", " 'ymin': [19, 20],\n", " 'lower': [20, 21],\n", " 'middle': [21, 22],\n", " 'upper': [22, 23],\n", " 'ymax': [23, 24],\n", " 'color': ['p', 'q'],\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_boxplot, box_identity_data4, stat='identity'),\n", " get_oriented_plot(geom_boxplot, box_identity_data4, stat='identity', swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_identity_data4, stat='identity', swap=True),\n", " get_oriented_plot(geom_boxplot, box_identity_data4, stat='identity', flip=True),\n", " get_oriented_plot(geom_boxplot, box_identity_data4, stat='identity', flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_identity_data4, stat='identity', flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 23, "id": "24446f29-6b87-4176-ac93-aa678c3ea2bb", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, one value for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_boxplot, box_identity_data4, stat='identity', orientation='y')" ] }, { "cell_type": "code", "execution_count": 24, "id": "a0a1ef4d-c94c-4745-a454-b956fae2234c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, few values for each color\n", "\n", "box_identity_data5 = {\n", " 'x': [-90, -90, -110],\n", " 'ymin': [-23, -24, -21],\n", " 'lower': [-22, -23, -20],\n", " 'middle': [-21, -22, -19],\n", " 'upper': [-20, -21, -18],\n", " 'ymax': [-19, -20, -17],\n", " 'color': ['p', 'q', 'p'],\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_boxplot, box_identity_data5, stat='identity'),\n", " get_oriented_plot(geom_boxplot, box_identity_data5, stat='identity', swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_identity_data5, stat='identity', swap=True),\n", " get_oriented_plot(geom_boxplot, box_identity_data5, stat='identity', flip=True),\n", " get_oriented_plot(geom_boxplot, box_identity_data5, stat='identity', flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_boxplot, box_identity_data5, stat='identity', flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 25, "id": "ce7eb65b-ad99-4580-b9d0-59d06145392d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, few values for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_boxplot, box_identity_data5, stat='identity', orientation='y')" ] }, { "cell_type": "markdown", "id": "6e540341-702b-4db8-bceb-1da270a6858c", "metadata": {}, "source": [ "### Violin" ] }, { "cell_type": "markdown", "id": "00915623-d49c-4be6-a730-6b57ca14b7cc", "metadata": {}, "source": [ "#### Default stat" ] }, { "cell_type": "code", "execution_count": 26, "id": "3f7608ca-7bcc-474d-8826-a1b18b3c4536", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# no x\n", "\n", "gggrid([\n", " get_oriented_plot(geom_violin, box_data1),\n", " get_oriented_plot(geom_violin, box_data1, swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, box_data1, swap=True),\n", " get_oriented_plot(geom_violin, box_data1, flip=True),\n", " get_oriented_plot(geom_violin, box_data1, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, box_data1, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 27, "id": "5e0430f8-37ee-45be-9b9d-85e789243df8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# no x\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_violin, box_data1, orientation='y')" ] }, { "cell_type": "code", "execution_count": 28, "id": "c649d76e-6f19-426d-9bf2-334ae308d838", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, one value for each color\n", "\n", "gggrid([\n", " get_oriented_plot(geom_violin, box_data2),\n", " get_oriented_plot(geom_violin, box_data2, swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, box_data2, swap=True),\n", " get_oriented_plot(geom_violin, box_data2, flip=True),\n", " get_oriented_plot(geom_violin, box_data2, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, box_data2, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 29, "id": "4d1d9e78-b603-49a6-a26c-0fec03183c34", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, one value for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_violin, box_data2, orientation='y')" ] }, { "cell_type": "code", "execution_count": 30, "id": "29bcce99-fa63-4ccc-8d7c-b7691c7a7ba7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, few values for each color\n", "\n", "gggrid([\n", " get_oriented_plot(geom_violin, box_data3),\n", " get_oriented_plot(geom_violin, box_data3, swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, box_data3, swap=True),\n", " get_oriented_plot(geom_violin, box_data3, flip=True),\n", " get_oriented_plot(geom_violin, box_data3, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, box_data3, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 31, "id": "aa8cafd5-5020-4618-8608-caf902166b52", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, few values for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_violin, box_data3, orientation='y')" ] }, { "cell_type": "code", "execution_count": 32, "id": "ef571896-7dd2-4f17-b4b2-73cb8a02ac77", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, one value for each color\n", "\n", "gggrid([\n", " get_oriented_plot(geom_violin, box_data4),\n", " get_oriented_plot(geom_violin, box_data4, swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, box_data4, swap=True),\n", " get_oriented_plot(geom_violin, box_data4, flip=True),\n", " get_oriented_plot(geom_violin, box_data4, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, box_data4, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 33, "id": "15c68d25-a862-4b7c-915b-a0509b95848a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, one value for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_violin, box_data4, orientation='y')" ] }, { "cell_type": "code", "execution_count": 34, "id": "8bf0b1b5-1d5a-4b10-899c-e9fb32a10a8c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, few values for each color\n", "\n", "gggrid([\n", " get_oriented_plot(geom_violin, box_data5),\n", " get_oriented_plot(geom_violin, box_data5, swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, box_data5, swap=True),\n", " get_oriented_plot(geom_violin, box_data5, flip=True),\n", " get_oriented_plot(geom_violin, box_data5, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, box_data5, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 35, "id": "03ed2024-de96-429c-a77f-b179e0225f07", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, few values for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_violin, box_data5, orientation='y')" ] }, { "cell_type": "markdown", "id": "8b027839-6940-4bda-a170-a87960a026f6", "metadata": {}, "source": [ "#### `stat='identity'`" ] }, { "cell_type": "code", "execution_count": 36, "id": "7cb106af-445c-4208-90e6-5198aee93912", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# no x\n", "\n", "violin_identity_data1 = {\n", " 'y': [19, 20, 21, 20, 21, 22],\n", " 'violinwidth': [.6, .8, .7, .7, .8, .6],\n", " 'color': ['p'] * 3 + ['q'] * 3,\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_violin, violin_identity_data1, stat='identity'),\n", " get_oriented_plot(geom_violin, violin_identity_data1, stat='identity', swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, violin_identity_data1, stat='identity', swap=True),\n", " get_oriented_plot(geom_violin, violin_identity_data1, stat='identity', flip=True),\n", " get_oriented_plot(geom_violin, violin_identity_data1, stat='identity', flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, violin_identity_data1, stat='identity', flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 37, "id": "df1e62bb-933c-47e1-95ba-c1fdf27ce61e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# no x\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_violin, violin_identity_data1, stat='identity', orientation='y')" ] }, { "cell_type": "code", "execution_count": 38, "id": "2d44a8a3-648c-47a9-a893-cda0c2c716c9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, one value for each color\n", "\n", "violin_identity_data2 = {\n", " 'x': ['a'] * 6,\n", " 'y': [19, 20, 21, 20, 21, 22],\n", " 'violinwidth': [.6, .8, .7, .7, .8, .6],\n", " 'color': ['p'] * 3 + ['q'] * 3,\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_violin, violin_identity_data2, stat='identity'),\n", " get_oriented_plot(geom_violin, violin_identity_data2, stat='identity', swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, violin_identity_data2, stat='identity', swap=True),\n", " get_oriented_plot(geom_violin, violin_identity_data2, stat='identity', flip=True),\n", " get_oriented_plot(geom_violin, violin_identity_data2, stat='identity', flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, violin_identity_data2, stat='identity', flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 39, "id": "5b2ba086-92e5-4d39-a040-df5fe0d21cd4", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, one value for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_violin, violin_identity_data2, stat='identity', orientation='y')" ] }, { "cell_type": "code", "execution_count": 40, "id": "6a74db8d-1352-43a0-ae72-d2469f14a6f4", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, few values for each color\n", "\n", "violin_identity_data3 = {\n", " 'x': ['a'] * 6 + ['b'] * 3,\n", " 'y': [-23, -24, -25, -24, -25, -26, -21, -22, -23],\n", " 'violinwidth': [.4, .8, .6] * 3,\n", " 'color': ['p'] * 3 + ['q'] * 3 + ['p'] * 3,\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_violin, violin_identity_data3, stat='identity'),\n", " get_oriented_plot(geom_violin, violin_identity_data3, stat='identity', swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, violin_identity_data3, stat='identity', swap=True),\n", " get_oriented_plot(geom_violin, violin_identity_data3, stat='identity', flip=True),\n", " get_oriented_plot(geom_violin, violin_identity_data3, stat='identity', flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, violin_identity_data3, stat='identity', flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 41, "id": "0d1d2bf2-1eb1-486e-8f41-71f799f01b41", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, few values for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_violin, violin_identity_data3, stat='identity', orientation='y')" ] }, { "cell_type": "code", "execution_count": 42, "id": "e5d6351e-c663-48ca-9fa0-f69178f29817", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, one value for each color\n", "\n", "violin_identity_data4 = {\n", " 'x': [100] * 6,\n", " 'y': [19, 20, 21, 20, 21, 22],\n", " 'violinwidth': [.6, .8, .7, .7, .8, .6],\n", " 'color': ['p'] * 3 + ['q'] * 3,\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_violin, violin_identity_data4, stat='identity'),\n", " get_oriented_plot(geom_violin, violin_identity_data4, stat='identity', swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, violin_identity_data4, stat='identity', swap=True),\n", " get_oriented_plot(geom_violin, violin_identity_data4, stat='identity', flip=True),\n", " get_oriented_plot(geom_violin, violin_identity_data4, stat='identity', flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, violin_identity_data4, stat='identity', flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 43, "id": "f50dd9b6-10ba-41ef-8f10-0a090ecd08e2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, one value for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_violin, violin_identity_data4, stat='identity', orientation='y')" ] }, { "cell_type": "code", "execution_count": 44, "id": "adc5163c-93fe-43c4-8b83-0ebe89635337", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, few values for each color\n", "\n", "violin_identity_data5 = {\n", " 'x': [-90] * 6 + [-100] * 3,\n", " 'y': [-23, -24, -25, -24, -25, -26, -21, -22, -23],\n", " 'violinwidth': [.4, .8, .6] * 3,\n", " 'color': ['p'] * 3 + ['q'] * 3 + ['p'] * 3,\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_violin, violin_identity_data5, stat='identity'),\n", " get_oriented_plot(geom_violin, violin_identity_data5, stat='identity', swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, violin_identity_data5, stat='identity', swap=True),\n", " get_oriented_plot(geom_violin, violin_identity_data5, stat='identity', flip=True),\n", " get_oriented_plot(geom_violin, violin_identity_data5, stat='identity', flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_violin, violin_identity_data5, stat='identity', flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 45, "id": "ebc275e6-fc34-420e-ab0e-e86b33178705", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, few values for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_violin, violin_identity_data5, stat='identity', orientation='y')" ] }, { "cell_type": "markdown", "id": "e98b3a0f-e2be-4a80-85d9-d2cd847deeef", "metadata": {}, "source": [ "### YDotplot" ] }, { "cell_type": "markdown", "id": "da807388-30a5-487c-ac45-2c35d7465bd1", "metadata": {}, "source": [ "#### Default stat" ] }, { "cell_type": "code", "execution_count": 46, "id": "fbf64b4e-8338-400d-b4d6-938ab8ae0b23", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# no x\n", "\n", "ydotplot_data1 = {\n", " 'y': [55, 53, 53, 47, 56, 50, 50, 48],\n", " 'fill': ['p'] * 4 + ['q'] * 4,\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_ydotplot, ydotplot_data1, parameters={'binwidth': 2}),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data1, parameters={'binwidth': 2}, swap=True, orientation='y'),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data1, parameters={'binwidth': 2}, swap=True),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data1, parameters={'binwidth': 2}, flip=True),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data1, parameters={'binwidth': 2}, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data1, parameters={'binwidth': 2}, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 47, "id": "0ad10240-d254-4625-8043-dc85a53ecc05", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# no x\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_ydotplot, ydotplot_data1, orientation='y')" ] }, { "cell_type": "code", "execution_count": 48, "id": "5526dc46-7d91-47f0-a8d3-e16c614f4ae7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, one value for each color\n", "\n", "ydotplot_data2 = {\n", " 'x': ['a'] * 8,\n", " 'y': [55, 53, 53, 47, 56, 50, 50, 48],\n", " 'fill': ['p'] * 4 + ['q'] * 4,\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_ydotplot, ydotplot_data2, parameters={'binwidth': 2}),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data2, parameters={'binwidth': 2}, swap=True, orientation='y'),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data2, parameters={'binwidth': 2}, swap=True),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data2, parameters={'binwidth': 2}, flip=True),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data2, parameters={'binwidth': 2}, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data2, parameters={'binwidth': 2}, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 49, "id": "6e88a77e-39e7-4a9e-ba49-22b2a2282ba4", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, one value for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_ydotplot, ydotplot_data2, orientation='y')" ] }, { "cell_type": "code", "execution_count": 50, "id": "4ef5d6d4-481b-4257-8c9e-7ca14dd44ef4", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, few values for each color\n", "\n", "ydotplot_data3 = {\n", " 'x': ['a'] * 8 + ['b'] * 4,\n", " 'y': [-55, -53, -53, -47, -56, -50, -50, -48,\n", " -50, -49, -46, -46],\n", " 'fill': ['p'] * 4 + ['q'] * 4 + ['p'] * 4,\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_ydotplot, ydotplot_data3, parameters={'binwidth': 1}),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data3, parameters={'binwidth': 1}, swap=True, orientation='y'),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data3, parameters={'binwidth': 1}, swap=True),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data3, parameters={'binwidth': 1}, flip=True),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data3, parameters={'binwidth': 1}, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data3, parameters={'binwidth': 1}, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 51, "id": "261d14ac-d0c1-46f0-bb11-186db016468b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, few values for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_ydotplot, ydotplot_data3, orientation='y')" ] }, { "cell_type": "code", "execution_count": 52, "id": "4a0c5017-9d5d-4307-9907-823d506601e0", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, one value for each color\n", "\n", "ydotplot_data4 = {\n", " 'x': [100] * 8,\n", " 'y': [55, 53, 53, 47, 56, 50, 50, 48],\n", " 'fill': ['p'] * 4 + ['q'] * 4,\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_ydotplot, ydotplot_data4, parameters={'binwidth': 2}),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data4, parameters={'binwidth': 2}, swap=True, orientation='y'),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data4, parameters={'binwidth': 2}, swap=True),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data4, parameters={'binwidth': 2}, flip=True),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data4, parameters={'binwidth': 2}, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data4, parameters={'binwidth': 2}, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 53, "id": "62995446-488b-4511-aeca-6ef3da5fa663", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 53, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, one value for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_ydotplot, ydotplot_data4, orientation='y')" ] }, { "cell_type": "code", "execution_count": 54, "id": "a800fac2-9cbf-4588-a9db-de41b8779fe2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 54, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, few values for each color\n", "\n", "ydotplot_data5 = {\n", " 'x': [95] * 8 + [105] * 4,\n", " 'y': [-55, -53, -53, -47, -56, -50, -50, -48,\n", " -50, -49, -46, -46],\n", " 'fill': ['p'] * 4 + ['q'] * 4 + ['p'] * 4,\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_ydotplot, ydotplot_data5, parameters={'binwidth': 1}),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data5, parameters={'binwidth': 1}, swap=True, orientation='y'),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data5, parameters={'binwidth': 1}, swap=True),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data5, parameters={'binwidth': 1}, flip=True),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data5, parameters={'binwidth': 1}, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(geom_ydotplot, ydotplot_data5, parameters={'binwidth': 1}, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 55, "id": "fd8547e3-5a69-4977-99d5-94c794c9ee95", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 55, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, few values for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(geom_ydotplot, ydotplot_data5, orientation='y')" ] }, { "cell_type": "markdown", "id": "7ab27486-faaa-49bc-ac4b-6928d108af04", "metadata": {}, "source": [ "### Crossbar" ] }, { "cell_type": "code", "execution_count": 56, "id": "cba3ec2b-8dc1-4e54-a003-ffe7beacd6cf", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 56, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# no x\n", "\n", "crossbar_data1 = {\n", " 'ymin': [19, 20],\n", " 'y': [20, 21],\n", " 'ymax': [21, 22],\n", " 'color': ['p', 'q'],\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_crossbar, crossbar_data1),\n", " get_oriented_plot(geom_crossbar, crossbar_data1, swap=True),\n", " get_oriented_plot(geom_crossbar, crossbar_data1, flip=True),\n", " get_oriented_plot(geom_crossbar, crossbar_data1, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 57, "id": "f7dcefdf-ed0b-4a65-a879-c93d9ade330a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 57, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, one value for each color\n", "\n", "crossbar_data2 = {\n", " 'x': ['a', 'a'],\n", " 'ymin': [19, 20],\n", " 'y': [20, 21],\n", " 'ymax': [21, 22],\n", " 'color': ['p', 'q'],\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_crossbar, crossbar_data2),\n", " get_oriented_plot(geom_crossbar, crossbar_data2, swap=True),\n", " get_oriented_plot(geom_crossbar, crossbar_data2, flip=True),\n", " get_oriented_plot(geom_crossbar, crossbar_data2, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 58, "id": "a4ce6bde-059d-4d2b-b508-7e738837b69e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 58, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, few values for each color\n", "\n", "crossbar_data3 = {\n", " 'x': ['a', 'a', 'b'],\n", " 'ymin': [19, 21, 20],\n", " 'y': [20, 22, 21],\n", " 'ymax': [21, 23, 22],\n", " 'color': ['p', 'q', 'p'],\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_crossbar, crossbar_data3),\n", " get_oriented_plot(geom_crossbar, crossbar_data3, swap=True),\n", " get_oriented_plot(geom_crossbar, crossbar_data3, flip=True),\n", " get_oriented_plot(geom_crossbar, crossbar_data3, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 59, "id": "511fc122-1de3-4cdf-83ac-8dbdb99ab0ad", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 59, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, one value for each color\n", "\n", "crossbar_data4 = {\n", " 'x': [50, 50],\n", " 'ymin': [19, 20],\n", " 'y': [20, 21],\n", " 'ymax': [21, 22],\n", " 'color': ['p', 'q'],\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_crossbar, crossbar_data4),\n", " get_oriented_plot(geom_crossbar, crossbar_data4, swap=True),\n", " get_oriented_plot(geom_crossbar, crossbar_data4, flip=True),\n", " get_oriented_plot(geom_crossbar, crossbar_data4, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 60, "id": "dd8b2d55-72f4-42c9-945b-0e621395114c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 60, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, few values for each color\n", "\n", "crossbar_data5 = {\n", " 'x': [95, 95, 105],\n", " 'ymin': [19, 21, 20],\n", " 'y': [20, 22, 21],\n", " 'ymax': [21, 23, 22],\n", " 'color': ['p', 'q', 'p'],\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_crossbar, crossbar_data5),\n", " get_oriented_plot(geom_crossbar, crossbar_data5, swap=True),\n", " get_oriented_plot(geom_crossbar, crossbar_data5, flip=True),\n", " get_oriented_plot(geom_crossbar, crossbar_data5, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "markdown", "id": "abb07ad6-8043-49ed-ad9f-e9763574a393", "metadata": {}, "source": [ "### Errorbar" ] }, { "cell_type": "code", "execution_count": 61, "id": "6da0ad23-860a-480e-93c8-152570c9f387", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 61, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# no x\n", "\n", "gggrid([\n", " get_oriented_plot(geom_errorbar, crossbar_data1),\n", " get_oriented_plot(geom_errorbar, crossbar_data1, swap=True),\n", " get_oriented_plot(geom_errorbar, crossbar_data1, flip=True),\n", " get_oriented_plot(geom_errorbar, crossbar_data1, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 62, "id": "916d7db0-fe45-4847-990c-1dd13bfcb541", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 62, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, one value for each color\n", "\n", "gggrid([\n", " get_oriented_plot(geom_errorbar, crossbar_data2),\n", " get_oriented_plot(geom_errorbar, crossbar_data2, swap=True),\n", " get_oriented_plot(geom_errorbar, crossbar_data2, flip=True),\n", " get_oriented_plot(geom_errorbar, crossbar_data2, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 63, "id": "70063eb0-15b2-4492-af5b-4b4044dbce6e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 63, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, few values for each color\n", "\n", "gggrid([\n", " get_oriented_plot(geom_errorbar, crossbar_data3),\n", " get_oriented_plot(geom_errorbar, crossbar_data3, swap=True),\n", " get_oriented_plot(geom_errorbar, crossbar_data3, flip=True),\n", " get_oriented_plot(geom_errorbar, crossbar_data3, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 64, "id": "85896356-b726-4bca-9abe-ee794ca89a99", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, one value for each color\n", "\n", "gggrid([\n", " get_oriented_plot(geom_errorbar, crossbar_data4),\n", " get_oriented_plot(geom_errorbar, crossbar_data4, swap=True),\n", " get_oriented_plot(geom_errorbar, crossbar_data4, flip=True),\n", " get_oriented_plot(geom_errorbar, crossbar_data4, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 65, "id": "5cd9d800-e12b-4dcc-b5c4-aa63f16fb151", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 65, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, few values for each color\n", "\n", "gggrid([\n", " get_oriented_plot(geom_errorbar, crossbar_data5),\n", " get_oriented_plot(geom_errorbar, crossbar_data5, swap=True),\n", " get_oriented_plot(geom_errorbar, crossbar_data5, flip=True),\n", " get_oriented_plot(geom_errorbar, crossbar_data5, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "markdown", "id": "cad231ea-5cda-44e3-8df3-5e3249269b89", "metadata": {}, "source": [ "### Linerange" ] }, { "cell_type": "code", "execution_count": 66, "id": "524e3486-11ca-450c-a838-6c56ea42a7ad", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 66, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# no x\n", "\n", "gggrid([\n", " get_oriented_plot(geom_linerange, crossbar_data1, parameters={'size': 5}),\n", " get_oriented_plot(geom_linerange, crossbar_data1, parameters={'size': 5}, swap=True),\n", " get_oriented_plot(geom_linerange, crossbar_data1, parameters={'size': 5}, flip=True),\n", " get_oriented_plot(geom_linerange, crossbar_data1, parameters={'size': 5}, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 67, "id": "af6c6ccd-edf6-48bc-8b7d-bdae838f9f7d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 67, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, one value for each color\n", "\n", "gggrid([\n", " get_oriented_plot(geom_linerange, crossbar_data2, parameters={'size': 5}),\n", " get_oriented_plot(geom_linerange, crossbar_data2, parameters={'size': 5}, swap=True),\n", " get_oriented_plot(geom_linerange, crossbar_data2, parameters={'size': 5}, flip=True),\n", " get_oriented_plot(geom_linerange, crossbar_data2, parameters={'size': 5}, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 68, "id": "b2ae92bc-85f2-4615-9dae-22c060a79402", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 68, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, few values for each color\n", "\n", "gggrid([\n", " get_oriented_plot(geom_linerange, crossbar_data3, parameters={'size': 5}),\n", " get_oriented_plot(geom_linerange, crossbar_data3, parameters={'size': 5}, swap=True),\n", " get_oriented_plot(geom_linerange, crossbar_data3, parameters={'size': 5}, flip=True),\n", " get_oriented_plot(geom_linerange, crossbar_data3, parameters={'size': 5}, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 69, "id": "b089a317-8db0-4325-903b-9827a9f4e2da", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, one value for each color\n", "\n", "gggrid([\n", " get_oriented_plot(geom_linerange, crossbar_data4, parameters={'size': 5}),\n", " get_oriented_plot(geom_linerange, crossbar_data4, parameters={'size': 5}, swap=True),\n", " get_oriented_plot(geom_linerange, crossbar_data4, parameters={'size': 5}, flip=True),\n", " get_oriented_plot(geom_linerange, crossbar_data4, parameters={'size': 5}, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 70, "id": "fa9d41c5-b90b-4c74-ae91-32b072f9ee06", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 70, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, few values for each color\n", "\n", "gggrid([\n", " get_oriented_plot(geom_linerange, crossbar_data5, parameters={'size': 5}),\n", " get_oriented_plot(geom_linerange, crossbar_data5, parameters={'size': 5}, swap=True),\n", " get_oriented_plot(geom_linerange, crossbar_data5, parameters={'size': 5}, flip=True),\n", " get_oriented_plot(geom_linerange, crossbar_data5, parameters={'size': 5}, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "markdown", "id": "3604f326-b72f-4765-9617-76607cc7f234", "metadata": {}, "source": [ "### Pointrange" ] }, { "cell_type": "code", "execution_count": 71, "id": "1af37d3d-6d10-44eb-9426-1d9648acd5db", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# no x\n", "\n", "gggrid([\n", " get_oriented_plot(geom_pointrange, crossbar_data1, parameters={'fatten': 10}),\n", " get_oriented_plot(geom_pointrange, crossbar_data1, parameters={'fatten': 10}, swap=True),\n", " get_oriented_plot(geom_pointrange, crossbar_data1, parameters={'fatten': 10}, flip=True),\n", " get_oriented_plot(geom_pointrange, crossbar_data1, parameters={'fatten': 10}, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 72, "id": "e943e206-46da-4808-8e04-8c5495139504", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 72, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, one value for each color\n", "\n", "gggrid([\n", " get_oriented_plot(geom_pointrange, crossbar_data2, parameters={'fatten': 10}),\n", " get_oriented_plot(geom_pointrange, crossbar_data2, parameters={'fatten': 10}, swap=True),\n", " get_oriented_plot(geom_pointrange, crossbar_data2, parameters={'fatten': 10}, flip=True),\n", " get_oriented_plot(geom_pointrange, crossbar_data2, parameters={'fatten': 10}, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 73, "id": "0241d835-97b5-4415-933f-7311cb13e969", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 73, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, few values for each color\n", "\n", "gggrid([\n", " get_oriented_plot(geom_pointrange, crossbar_data3, parameters={'fatten': 10}),\n", " get_oriented_plot(geom_pointrange, crossbar_data3, parameters={'fatten': 10}, swap=True),\n", " get_oriented_plot(geom_pointrange, crossbar_data3, parameters={'fatten': 10}, flip=True),\n", " get_oriented_plot(geom_pointrange, crossbar_data3, parameters={'fatten': 10}, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 74, "id": "1700927e-3744-447c-ab45-e91e96807366", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, one value for each color\n", "\n", "gggrid([\n", " get_oriented_plot(geom_pointrange, crossbar_data4, parameters={'fatten': 10}),\n", " get_oriented_plot(geom_pointrange, crossbar_data4, parameters={'fatten': 10}, swap=True),\n", " get_oriented_plot(geom_pointrange, crossbar_data4, parameters={'fatten': 10}, flip=True),\n", " get_oriented_plot(geom_pointrange, crossbar_data4, parameters={'fatten': 10}, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 75, "id": "e2d8914d-2b8e-4f37-b7f0-c3e8d128dc60", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 75, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, few values for each color\n", "\n", "gggrid([\n", " get_oriented_plot(geom_pointrange, crossbar_data5, parameters={'fatten': 10}),\n", " get_oriented_plot(geom_pointrange, crossbar_data5, parameters={'fatten': 10}, swap=True),\n", " get_oriented_plot(geom_pointrange, crossbar_data5, parameters={'fatten': 10}, flip=True),\n", " get_oriented_plot(geom_pointrange, crossbar_data5, parameters={'fatten': 10}, flip=True, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "markdown", "id": "cf2596af-2115-45bc-b4c6-f66742a56950", "metadata": {}, "source": [ "### Summary stat" ] }, { "cell_type": "code", "execution_count": 76, "id": "8c6fc07d-b0c5-4895-9b60-039ff522a8ab", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 76, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# no x\n", "\n", "gggrid([\n", " get_oriented_plot(stat_summary, box_data1),\n", " get_oriented_plot(stat_summary, box_data1, swap=True, orientation='y'),\n", " get_oriented_plot(stat_summary, box_data1, swap=True),\n", " get_oriented_plot(stat_summary, box_data1, flip=True),\n", " get_oriented_plot(stat_summary, box_data1, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(stat_summary, box_data1, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 77, "id": "a26c060a-5a8e-4473-aac1-7f64c9d5113d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 77, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# no x\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(stat_summary, box_data1, orientation='y')" ] }, { "cell_type": "code", "execution_count": 78, "id": "bde4b01d-1daf-4c8a-81e1-6fbad38df730", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 78, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, one value for each color\n", "\n", "gggrid([\n", " get_oriented_plot(stat_summary, box_data2),\n", " get_oriented_plot(stat_summary, box_data2, swap=True, orientation='y'),\n", " get_oriented_plot(stat_summary, box_data2, swap=True),\n", " get_oriented_plot(stat_summary, box_data2, flip=True),\n", " get_oriented_plot(stat_summary, box_data2, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(stat_summary, box_data2, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 79, "id": "eac34033-b639-4836-b0fc-d0b2cde89fcd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, one value for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(stat_summary, box_data2, orientation='y')" ] }, { "cell_type": "code", "execution_count": 80, "id": "c42886c8-c94f-41ae-862a-068fc269cc48", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 80, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, few values for each color\n", "\n", "gggrid([\n", " get_oriented_plot(stat_summary, box_data3),\n", " get_oriented_plot(stat_summary, box_data3, swap=True, orientation='y'),\n", " get_oriented_plot(stat_summary, box_data3, swap=True),\n", " get_oriented_plot(stat_summary, box_data3, flip=True),\n", " get_oriented_plot(stat_summary, box_data3, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(stat_summary, box_data3, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 81, "id": "7dae7f34-ec8e-443f-a923-094fbe37d468", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 81, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x discrete, few values for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(stat_summary, box_data3, orientation='y')" ] }, { "cell_type": "code", "execution_count": 82, "id": "2a933f1c-7737-44e2-a144-7cef4cd1a934", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 82, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, one value for each color\n", "\n", "gggrid([\n", " get_oriented_plot(stat_summary, box_data4),\n", " get_oriented_plot(stat_summary, box_data4, swap=True, orientation='y'),\n", " get_oriented_plot(stat_summary, box_data4, swap=True),\n", " get_oriented_plot(stat_summary, box_data4, flip=True),\n", " get_oriented_plot(stat_summary, box_data4, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(stat_summary, box_data4, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 83, "id": "46eb6cd2-5a71-4102-9593-d09df1116014", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 83, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, one value for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(stat_summary, box_data4, orientation='y')" ] }, { "cell_type": "code", "execution_count": 84, "id": "9840e8a3-2040-45c5-b7a3-48f5b74cb692", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 84, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, few values for each color\n", "\n", "gggrid([\n", " get_oriented_plot(stat_summary, box_data5),\n", " get_oriented_plot(stat_summary, box_data5, swap=True, orientation='y'),\n", " get_oriented_plot(stat_summary, box_data5, swap=True),\n", " get_oriented_plot(stat_summary, box_data5, flip=True),\n", " get_oriented_plot(stat_summary, box_data5, flip=True, swap=True, orientation='y'),\n", " get_oriented_plot(stat_summary, box_data5, flip=True, swap=True),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 85, "id": "d73f9bc0-55dd-44d4-a1d8-b6259292927b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 85, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# x continuous, few values for each color\n", "# only change the orientation, not the mappings\n", "# NOTE: it's not expected to work\n", "get_oriented_plot(stat_summary, box_data5, orientation='y')" ] }, { "cell_type": "markdown", "id": "698e9327-fd89-464c-a767-42299b16343b", "metadata": {}, "source": [ "## Additional tests" ] }, { "cell_type": "markdown", "id": "a05a2e3e-3ba1-42fc-9ef5-f2fa3d421292", "metadata": {}, "source": [ "### Tooltips" ] }, { "cell_type": "code", "execution_count": 86, "id": "b58721c1-429b-4c7e-81fd-97af13b69c59", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 86, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def get_boxplot_tooltips_plot(data, constants, *, swap=False, orientation=None, stat=None):\n", " mapping = {aes_name(col_name, swap): col_name for col_name, col_values in data.items()}\n", " scale_pos = scale_x_continuous if swap else scale_y_continuous\n", " tooltips = layer_tooltips()\n", " for aes_key in [\"lower\", \"middle\", \"upper\"]:\n", " swapped_aes_key = aes_name(aes_key, swap)\n", " tooltip_aes_key = \"^\" + swapped_aes_key\n", " tooltips = tooltips.line(\"{name} ({const}{formatted})|{tooltip_name}\".format(\n", " name=swapped_aes_key,\n", " const=\"const\" if aes_key in constants else \"var\",\n", " formatted=\"\" if aes_key == \"middle\" else \", formatted\",\n", " tooltip_name=tooltip_aes_key,\n", " ))\n", " if aes_key != \"middle\":\n", " tooltips = tooltips.format(tooltip_aes_key, \"[{.1f}]\")\n", " return ggplot(data, aes(**mapping)) + \\\n", " geom_boxplot(stat=stat, orientation=orientation, tooltips=tooltips,\n", " **{aes_name(k, swap): v for k, v in constants.items()}) + \\\n", " scale_pos(format=\".3f\") + \\\n", " ggtitle(\"{swap}stat={stat}, orientation={o}{expected}\".format(\n", " stat=stat,\n", " o=orientation,\n", " swap=\"mapping is inverse\\n\" if swap else \"\",\n", " expected=\"\\nEXPECTED:\\n- tooltips for lower, middle, upper\\n- side tooltip for ymax\\n- axis tooltip for categorical axis\",\n", " ))\n", "\n", "box_constants3 = {'ymin': -57, 'lower': -56, 'middle': -53}\n", "box_identity_constants3 = {'ymin': -25, 'lower': -24, 'middle': -23}\n", "gggrid([\n", " get_boxplot_tooltips_plot(box_data3, box_constants3),\n", " get_boxplot_tooltips_plot(box_data3, box_constants3, swap=True),\n", " get_boxplot_tooltips_plot(box_data3, box_constants3, orientation='x'),\n", " get_boxplot_tooltips_plot(box_data3, box_constants3, swap=True, orientation='y'),\n", " get_boxplot_tooltips_plot(box_identity_data3, box_identity_constants3, stat='identity'),\n", " get_boxplot_tooltips_plot(box_identity_data3, box_identity_constants3, stat='identity', swap=True),\n", " get_boxplot_tooltips_plot(box_identity_data3, box_identity_constants3, stat='identity', orientation='x'),\n", " get_boxplot_tooltips_plot(box_identity_data3, box_identity_constants3, stat='identity', swap=True, orientation='y'),\n", "], ncol=2)" ] }, { "cell_type": "markdown", "id": "13c679e5-b81c-4699-8a43-a73e7f6cee6a", "metadata": {}, "source": [ "### Constants (regression)" ] }, { "cell_type": "code", "execution_count": 87, "id": "af27d119-d182-4533-b694-b6d524bb566c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 87, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gggrid([\n", " ggplot(box_data3, aes('x', 'y', color='color')) + \\\n", " geom_boxplot(ymin=-57) + \\\n", " scale_y_continuous(trans='symlog') + \\\n", " ggtitle(\"EXPECTED: correct plot\"),\n", " ggplot(box_data3, aes('y', 'x', color='color')) + \\\n", " geom_boxplot(xmin=-57) + \\\n", " scale_x_continuous(trans='symlog') + \\\n", " ggtitle(\"EXPECTED: correct plot\"),\n", " ggplot(box_identity_data3, aes(x='x', lower='lower', middle='middle', upper='upper', ymax='ymax', color='color')) + \\\n", " geom_boxplot(stat='identity', ymin=-25) + \\\n", " scale_y_continuous(trans='symlog') + \\\n", " ggtitle(\"EXPECTED: correct plot\"),\n", " ggplot(box_identity_data3, aes(y='x', xlower='lower', xmiddle='middle', xupper='upper', xmax='ymax', color='color')) + \\\n", " geom_boxplot(stat='identity', xmin=-25) + \\\n", " scale_x_continuous(trans='symlog') + \\\n", " ggtitle(\"EXPECTED: correct plot\"),\n", "], ncol=2)" ] }, { "cell_type": "markdown", "id": "85a8d286-b0db-4558-ba57-37b9b1c5e3d2", "metadata": {}, "source": [ "### Marginal layers (regression)" ] }, { "cell_type": "code", "execution_count": 88, "id": "9f809775-eaa5-44a8-851b-224735774b14", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 88, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def marginal_layer_plot(geom, parameters={}):\n", " data = {\n", " 'x': [i**1.3 for i in range(10)] + [i**1.7 for i in range(10)],\n", " 'y': list(range(10)) + [4.5 - i / 2.0 for i in range(10)],\n", " 'color': ['a'] * 10 + ['b'] * 10,\n", " }\n", " geom_name = geom.__name__\n", " return ggplot(data, aes('x', 'y', color='color', fill='color')) + \\\n", " geom_point(size=5, alpha=.5) + \\\n", " scale_x_continuous(trans='sqrt') + \\\n", " ggmarginal(\"tr\", layer=geom(alpha=.5, **parameters)) + \\\n", " ggtitle(\"{0}({1})\\nEXPECTED: correct plot\".format(\n", " geom_name,\n", " \", \".join([\"{0}='{1}'\".format(k, v) for k, v in parameters.items()])\n", " ))\n", "\n", "gggrid([\n", " marginal_layer_plot(geom_boxplot),\n", " marginal_layer_plot(geom_violin),\n", " marginal_layer_plot(geom_ydotplot),\n", " marginal_layer_plot(stat_summary),\n", " marginal_layer_plot(geom_crossbar, {'stat': 'boxplot', 'position': 'dodge'}),\n", " marginal_layer_plot(geom_crossbar, {'stat': 'summary', 'position': 'dodge'}),\n", " marginal_layer_plot(geom_errorbar, {'stat': 'boxplot', 'position': 'dodge'}),\n", " marginal_layer_plot(geom_errorbar, {'stat': 'summary', 'position': 'dodge'}),\n", " marginal_layer_plot(geom_linerange, {'stat': 'boxplot', 'position': 'dodge'}),\n", " marginal_layer_plot(geom_linerange, {'stat': 'summary', 'position': 'dodge'}),\n", " marginal_layer_plot(geom_pointrange, {'stat': 'boxplot', 'position': 'dodge'}),\n", " marginal_layer_plot(geom_pointrange, {'stat': 'summary', 'position': 'dodge'}),\n", " marginal_layer_plot(geom_density),\n", " marginal_layer_plot(geom_histogram, {'binwidth': 2}),\n", "], ncol=2)" ] }, { "cell_type": "markdown", "id": "7eccd360-2513-445d-9f4b-2d123f1fe004", "metadata": {}, "source": [ "### Extra aesthetics" ] }, { "cell_type": "code", "execution_count": 89, "id": "3301d6f4-cf81-42bf-a379-85941c4966a2", "metadata": {}, "outputs": [], "source": [ "def extra_aes_plot(xs=None, ys=None):\n", " extra_data_x = {\n", " 'ymin': [-104, -102],\n", " 'lower': [-102, -101],\n", " 'middle': [-100, -100],\n", " 'upper': [-98, -99],\n", " 'ymax': [-96, -98],\n", " }\n", " if xs is not None:\n", " extra_data_x['x'] = xs\n", " extra_data_y = {\n", " 'xmin': [90, 94],\n", " 'xlower': [95, 97],\n", " 'xmiddle': [100, 100],\n", " 'xupper': [105, 103],\n", " 'xmax': [110, 106],\n", " }\n", " if ys is not None:\n", " extra_data_y['y'] = ys\n", " extra_data = {**extra_data_x, **extra_data_y}\n", " \n", " data_to_mapping = lambda d: {col: col for col, v in d.items()}\n", " extra_mapping_x = data_to_mapping(extra_data_x)\n", " extra_mapping_y = data_to_mapping(extra_data_y)\n", " extra_mapping = data_to_mapping(extra_data)\n", " \n", " print_mapping = lambda m, name: print(\"Mapping {0}:\\n{1}\\n\".format(\n", " name,\n", " '\\n'.join([\" {0}: {1}\".format(k, v) for k, v in m.items()])\n", " ))\n", " print_mapping(extra_mapping_x, \"extra_mapping_x\")\n", " print_mapping(extra_mapping_y, \"extra_mapping_y\")\n", " print_mapping(extra_mapping, \"extra_mapping\")\n", " \n", " return gggrid([\n", " ggplot(extra_data_x, aes(**extra_mapping_x)) + \\\n", " geom_boxplot(stat='identity') + \\\n", " ggtitle(\"x\\nEXPECTED: nothing\"),\n", " ggplot(extra_data_y, aes(**extra_mapping_y)) + \\\n", " geom_boxplot(stat='identity') + \\\n", " ggtitle(\"y\\nEXPECTED: nothing\"),\n", " ggplot(extra_data, aes(**extra_mapping)) + \\\n", " geom_boxplot(stat='identity') + \\\n", " ggtitle(\"both\\nEXPECTED: nothing\"),\n", " ggplot(extra_data, aes(**extra_mapping)) + \\\n", " geom_boxplot(stat='identity', orientation='x') + \\\n", " ggtitle(\"both, orientation='x'\\nEXPECTED: nothing\"),\n", " ggplot(extra_data, aes(**extra_mapping)) + \\\n", " geom_boxplot(stat='identity', orientation='y') + \\\n", " ggtitle(\"both, orientation='y'\\nEXPECTED: nothing\"),\n", " ], ncol=3)" ] }, { "cell_type": "code", "execution_count": 90, "id": "60d0a8d2-a3b8-4035-85dc-c911089cd8e2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Mapping extra_mapping_x:\n", " ymin: ymin\n", " lower: lower\n", " middle: middle\n", " upper: upper\n", " ymax: ymax\n", "\n", "Mapping extra_mapping_y:\n", " xmin: xmin\n", " xlower: xlower\n", " xmiddle: xmiddle\n", " xupper: xupper\n", " xmax: xmax\n", "\n", "Mapping extra_mapping:\n", " ymin: ymin\n", " lower: lower\n", " middle: middle\n", " upper: upper\n", " ymax: ymax\n", " xmin: xmin\n", " xlower: xlower\n", " xmiddle: xmiddle\n", " xupper: xupper\n", " xmax: xmax\n", "\n" ] }, { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 90, "metadata": {}, "output_type": "execute_result" } ], "source": [ "extra_aes_plot()" ] }, { "cell_type": "code", "execution_count": 91, "id": "ae956851-876b-48b0-aabe-bf530481f3dc", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Mapping extra_mapping_x:\n", " ymin: ymin\n", " lower: lower\n", " middle: middle\n", " upper: upper\n", " ymax: ymax\n", " x: x\n", "\n", "Mapping extra_mapping_y:\n", " xmin: xmin\n", " xlower: xlower\n", " xmiddle: xmiddle\n", " xupper: xupper\n", " xmax: xmax\n", " y: y\n", "\n", "Mapping extra_mapping:\n", " ymin: ymin\n", " lower: lower\n", " middle: middle\n", " upper: upper\n", " ymax: ymax\n", " x: x\n", " xmin: xmin\n", " xlower: xlower\n", " xmiddle: xmiddle\n", " xupper: xupper\n", " xmax: xmax\n", " y: y\n", "\n" ] }, { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 91, "metadata": {}, "output_type": "execute_result" } ], "source": [ "extra_aes_plot(['a', 'b'], ['c', 'd'])" ] }, { "cell_type": "code", "execution_count": 92, "id": "f1cab6c9-9ea4-4534-a0ed-e284893acf24", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Mapping extra_mapping_x:\n", " ymin: ymin\n", " lower: lower\n", " middle: middle\n", " upper: upper\n", " ymax: ymax\n", " x: x\n", "\n", "Mapping extra_mapping_y:\n", " xmin: xmin\n", " xlower: xlower\n", " xmiddle: xmiddle\n", " xupper: xupper\n", " xmax: xmax\n", " y: y\n", "\n", "Mapping extra_mapping:\n", " ymin: ymin\n", " lower: lower\n", " middle: middle\n", " upper: upper\n", " ymax: ymax\n", " x: x\n", " xmin: xmin\n", " xlower: xlower\n", " xmiddle: xmiddle\n", " xupper: xupper\n", " xmax: xmax\n", " y: y\n", "\n" ] }, { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" } ], "source": [ "extra_aes_plot([2, 4], [-3, -6])" ] }, { "cell_type": "markdown", "id": "b28f7c9e-7c8f-4e2c-b3eb-373212a579d9", "metadata": {}, "source": [ "### Positioning (regression)" ] }, { "cell_type": "code", "execution_count": 93, "id": "edaee829-e608-4b13-98f7-77cef68ea378", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 93, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gggrid([\n", " get_oriented_plot(geom_errorbar, crossbar_data1, parameters={'position': None}) + \\\n", " ggtitle(\"no x\\nposition=None\\nEXPECTED: identity pos\", \"Default orientation\"),\n", " get_oriented_plot(geom_errorbar, crossbar_data1, parameters={'position': 'dodge'}) + \\\n", " ggtitle(\"no x\\nposition='dodge'\\nEXPECTED: small gaps around\", \"Default orientation\"),\n", " get_oriented_plot(geom_errorbar, crossbar_data1, parameters={'position': position_dodge(.95)}) + \\\n", " ggtitle(\"no x\\nposition=position_dodge(.95)\\nEXPECTED: as previous\", \"Default orientation\"),\n", " get_oriented_plot(geom_errorbar, crossbar_data1, parameters={'position': None}, swap=True, orientation='y') + \\\n", " ggtitle(\"no x\\nposition=None\\nEXPECTED: identity pos\", \"orientation='y'\"),\n", " get_oriented_plot(geom_errorbar, crossbar_data1, parameters={'position': 'dodge'}, swap=True, orientation='y') + \\\n", " ggtitle(\"no x\\nposition='dodge'\\nEXPECTED: small gaps around\", \"orientation='y'\"),\n", " get_oriented_plot(geom_errorbar, crossbar_data1, parameters={'position': position_dodge(.95)}, swap=True, orientation='y') + \\\n", " ggtitle(\"no x\\nposition=position_dodge(.95)\\nEXPECTED: as previous\", \"orientation='y'\"),\n", " get_oriented_plot(geom_errorbar, crossbar_data2, parameters={'position': None}) + \\\n", " ggtitle(\"discrete x\\nposition=None\\nEXPECTED: identity pos\", \"Default orientation\"),\n", " get_oriented_plot(geom_errorbar, crossbar_data2, parameters={'position': 'dodge'}) + \\\n", " ggtitle(\"discrete x\\nposition='dodge'\\nEXPECTED: small gaps around\", \"Default orientation\"),\n", " get_oriented_plot(geom_errorbar, crossbar_data2, parameters={'position': position_dodge(.95)}) + \\\n", " ggtitle(\"discrete x\\nposition=position_dodge(.95)\\nEXPECTED: as previous\", \"Default orientation\"),\n", " get_oriented_plot(geom_errorbar, crossbar_data2, parameters={'position': None}, swap=True, orientation='y') + \\\n", " ggtitle(\"discrete x\\nposition=None\\nEXPECTED: identity pos\", \"orientation='y'\"),\n", " get_oriented_plot(geom_errorbar, crossbar_data2, parameters={'position': 'dodge'}, swap=True, orientation='y') + \\\n", " ggtitle(\"discrete x\\nposition='dodge'\\nEXPECTED: small gaps around\", \"orientation='y'\"),\n", " get_oriented_plot(geom_errorbar, crossbar_data2, parameters={'position': position_dodge(.95)}, swap=True, orientation='y') + \\\n", " ggtitle(\"discrete x\\nposition=position_dodge(.95)\\nEXPECTED: as previous\", \"orientation='y'\"),\n", " get_oriented_plot(geom_errorbar, crossbar_data4, parameters={'position': None}) + \\\n", " ggtitle(\"continuous x\\nposition=None\\nEXPECTED: identity pos\", \"Default orientation\"),\n", " get_oriented_plot(geom_errorbar, crossbar_data4, parameters={'position': 'dodge'}) + \\\n", " ggtitle(\"continuous x\\nposition='dodge'\\nEXPECTED: small gaps around\", \"Default orientation\"),\n", " get_oriented_plot(geom_errorbar, crossbar_data4, parameters={'position': position_dodge(.95)}) + \\\n", " ggtitle(\"continuous x\\nposition=position_dodge(.95)\\nEXPECTED: as previous\", \"Default orientation\"),\n", " get_oriented_plot(geom_errorbar, crossbar_data4, parameters={'position': None}, swap=True, orientation='y') + \\\n", " ggtitle(\"continuous x\\nposition=None\\nEXPECTED: identity pos\", \"orientation='y'\"),\n", " get_oriented_plot(geom_errorbar, crossbar_data4, parameters={'position': 'dodge'}, swap=True, orientation='y') + \\\n", " ggtitle(\"continuous x\\nposition='dodge'\\nEXPECTED: small gaps around\", \"orientation='y'\"),\n", " get_oriented_plot(geom_errorbar, crossbar_data4, parameters={'position': position_dodge(.95)}, swap=True, orientation='y') + \\\n", " ggtitle(\"continuous x\\nposition=position_dodge(.95)\\nEXPECTED: as previous\", \"orientation='y'\"),\n", "], ncol=3)" ] }, { "cell_type": "markdown", "id": "3260e079-eaa9-43ab-ac6a-b882482359ac", "metadata": {}, "source": [ "### Midline (regression)" ] }, { "cell_type": "code", "execution_count": 94, "id": "7c52d43d-9c84-46eb-afe0-bc4a0cf5b5d0", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 94, "metadata": {}, "output_type": "execute_result" } ], "source": [ "no_midline_data1 = {\n", " 'ymin': [-23, -22],\n", " 'ymax': [-21, -20],\n", " 'color': ['a', 'b'],\n", "}\n", "mo_midline_data2 = {\n", " 'x': [100, 100],\n", " 'ymin': [-23, -22],\n", " 'ymax': [-21, -20],\n", " 'color': ['a', 'b'],\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_crossbar, no_midline_data1),\n", " get_oriented_plot(geom_crossbar, mo_midline_data2),\n", " get_oriented_plot(geom_crossbar, no_midline_data1, swap=True),\n", " get_oriented_plot(geom_crossbar, mo_midline_data2, swap=True),\n", " get_oriented_plot(geom_pointrange, no_midline_data1),\n", " get_oriented_plot(geom_pointrange, mo_midline_data2),\n", " get_oriented_plot(geom_pointrange, no_midline_data1, swap=True),\n", " get_oriented_plot(geom_pointrange, mo_midline_data2, swap=True),\n", "], ncol=2)" ] }, { "cell_type": "markdown", "id": "d372a39e-21c6-4b12-afd2-15370a0e352f", "metadata": {}, "source": [ "### `coord_map()` (regression)" ] }, { "cell_type": "code", "execution_count": 95, "id": "8b7383d1-492e-48cf-99d4-082d7731a98c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 95, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def coord_map_plot(geom, orientation, *, min_aes='ymin', max_aes='ymax', middle_aes=None):\n", " cat_aes = 'x'\n", " cat_value = -15\n", " min_value, middle_value, max_value = 19, 20, 21\n", " aes_constants = {cat_aes: cat_value, min_aes: min_value, max_aes: max_value}\n", " if middle_aes is not None:\n", " aes_constants[middle_aes] = middle_value\n", " if orientation == 'y':\n", " aes_constants = {aes_name(k, True): v for k, v in aes_constants.items()}\n", " \n", " return ggplot() + \\\n", " geom(stat='identity', size=3, color='green', **aes_constants) + \\\n", " geom_segment(size=1, color='red',\n", " **{aes_name('x', orientation == 'y'): cat_value,\n", " aes_name('y', orientation == 'y'): min_value,\n", " aes_name('xend', orientation == 'y'): cat_value,\n", " aes_name('yend', orientation == 'y'): max_value}) + \\\n", " coord_map() + \\\n", " ggtitle(\"{0}()\\nEXPECTED: green interval\\nlimited by the red line\".format(\n", " geom.__name__\n", " ))\n", "\n", "gggrid([\n", " coord_map_plot(geom_crossbar, 'x'), coord_map_plot(geom_crossbar, 'y'),\n", " coord_map_plot(geom_errorbar, 'x'), coord_map_plot(geom_errorbar, 'y'),\n", " coord_map_plot(geom_linerange, 'x'), coord_map_plot(geom_linerange, 'y'),\n", " coord_map_plot(geom_pointrange, 'x', middle_aes='y'), coord_map_plot(geom_pointrange, 'y', middle_aes='y'),\n", " coord_map_plot(geom_boxplot, 'x', min_aes='lower', max_aes='upper'), coord_map_plot(geom_boxplot, 'y', min_aes='lower', max_aes='upper'),\n", "], ncol=2)" ] }, { "cell_type": "markdown", "id": "cabcee05-f9a0-4dcd-8b91-93037d3dc79a", "metadata": {}, "source": [ "### Other geoms that may have broken\n", "\n", "These geometries are either \"oriented\" (not symmetrical about the axes) or have \"positional\" aesthetics (`ymin`, `lower`, ...).\n", "\n", "With own stat:\n", "\n", "- `geom_bar()` (oriented)\n", "- `geom_smooth()` (`ymin`/`ymax`)\n", "\n", "Without stat:\n", "\n", "- `geom_ribbon()` (`ymin`/`ymax`)\n", "- `geom_lollipop()` (oriented)\n", "- `geom_band()` (`ymin`/`ymax`)" ] }, { "cell_type": "markdown", "id": "f05c46cc-dd1c-4cb4-b34b-4b2d42ed9cb4", "metadata": {}, "source": [ "#### `geom_bar()`" ] }, { "cell_type": "code", "execution_count": 96, "id": "8bcf0337-6fbb-415d-a99c-ca7b99079032", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 96, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar_data = {\n", " 'x': ['a', 'a', 'b'],\n", "}\n", "\n", "bar_identity_data = {\n", " 'x': ['a', 'b'],\n", " 'y': [1, 2],\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_bar, bar_data),\n", " get_oriented_plot(geom_bar, bar_data, swap=True, orientation='y'),\n", " get_oriented_plot(geom_bar, bar_data, swap=True),\n", " get_oriented_plot(geom_bar, bar_identity_data, stat='identity'),\n", " get_oriented_plot(geom_bar, bar_identity_data, stat='identity', swap=True, orientation='y', expected_text=\"correct plot\"),\n", " get_oriented_plot(geom_bar, bar_identity_data, stat='identity', swap=True, expected_text=\"correct plot\"),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 97, "id": "2f42bb06-e347-4337-a410-22a4836758ed", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 97, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# With polar coordinates (regression)\n", "\n", "gggrid([\n", " get_oriented_plot(geom_bar, bar_data) + \\\n", " coord_polar() + \\\n", " theme(axis_title='blank', axis_text_y='blank'),\n", " get_oriented_plot(geom_bar, bar_data, swap=True, orientation='y') + \\\n", " coord_polar() + \\\n", " theme(axis_title='blank', axis_text_x='blank'),\n", " get_oriented_plot(geom_bar, bar_data, swap=True) + \\\n", " coord_polar() + \\\n", " theme(axis_title='blank', axis_text_x='blank'),\n", " get_oriented_plot(geom_bar, bar_identity_data, stat='identity') + \\\n", " coord_polar() + \\\n", " theme(axis_title='blank', axis_text_y='blank'),\n", " get_oriented_plot(geom_bar, bar_identity_data, stat='identity', swap=True, orientation='y', expected_text=\"correct plot\") + \\\n", " coord_polar() + \\\n", " theme(axis_title='blank', axis_text_x='blank'),\n", " get_oriented_plot(geom_bar, bar_identity_data, stat='identity', swap=True, expected_text=\"correct plot\") + \\\n", " coord_polar() + \\\n", " theme(axis_title='blank', axis_text_x='blank'),\n", "], ncol=3)" ] }, { "cell_type": "markdown", "id": "ec32b2b9-e165-43e9-a3f7-8e92246822fb", "metadata": {}, "source": [ "#### `geom_smooth()`" ] }, { "cell_type": "code", "execution_count": 98, "id": "c8f3613c-f62e-4fa2-a741-defa119f9242", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 98, "metadata": {}, "output_type": "execute_result" } ], "source": [ "smooth_data = {\n", " 'x': [0, 1, 2],\n", " 'y': [0, .8, 2.2],\n", "}\n", "\n", "smooth_identity_data = {\n", " 'x': [-1, 0, 1],\n", " 'ymin': [-2.5, -.25, 0],\n", " 'y': [-2, 0, .5],\n", " 'ymax': [-1, .5, 1.5],\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_smooth, smooth_data),\n", " get_oriented_plot(geom_smooth, smooth_data, swap=True, orientation='y'),\n", " get_oriented_plot(geom_smooth, smooth_data, swap=True),\n", " get_oriented_plot(geom_smooth, smooth_identity_data, stat='identity'),\n", " get_oriented_plot(geom_smooth, smooth_identity_data, stat='identity', swap=True, orientation='y'),\n", " get_oriented_plot(geom_smooth, smooth_identity_data, stat='identity', swap=True),\n", "], ncol=3)" ] }, { "cell_type": "markdown", "id": "bac9303b-dcbb-48e9-b313-c4f1954c79f7", "metadata": {}, "source": [ "#### `geom_ribbon()`" ] }, { "cell_type": "code", "execution_count": 99, "id": "325fa37f-ad9e-44f1-9ef3-3e83cea3f809", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 99, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ribbon_data = {\n", " 'x': [-1, 1],\n", " 'ymin': [-2, -1],\n", " 'ymax': [1, 2],\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_ribbon, ribbon_data),\n", " get_oriented_plot(geom_ribbon, ribbon_data, swap=True, expected_text=\"correct plot\"),\n", "], ncol=3)" ] }, { "cell_type": "markdown", "id": "b6c32b44-b5e0-495c-b4b3-22adca46c94b", "metadata": {}, "source": [ "#### `geom_lollipop()`" ] }, { "cell_type": "code", "execution_count": 100, "id": "e63aef20-c559-4e9c-a7c1-a693de8df9de", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 100, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lollipop_data = {\n", " 'x': [2, 3],\n", " 'y': [12, 8],\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_lollipop, lollipop_data),\n", " get_oriented_plot(geom_lollipop, lollipop_data, swap=True, orientation='y'),\n", " get_oriented_plot(geom_lollipop, lollipop_data, swap=True, expected_text=\"correct plot\"),\n", "], ncol=3)" ] }, { "cell_type": "markdown", "id": "889fe1c5-3fe1-404c-ad02-48132b7116a4", "metadata": {}, "source": [ "#### `geom_band()`" ] }, { "cell_type": "code", "execution_count": 101, "id": "a47ec103-b433-42c6-8080-961ac6970a17", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 101, "metadata": {}, "output_type": "execute_result" } ], "source": [ "band_data = {\n", " 'ymin': [-4, 2],\n", " 'ymax': [-2, 4],\n", "}\n", "\n", "gggrid([\n", " get_oriented_plot(geom_band, band_data),\n", " get_oriented_plot(geom_band, band_data, swap=True, expected_text=\"correct plot\"),\n", "], ncol=3)" ] }, { "cell_type": "code", "execution_count": 102, "id": "12dbb04a-214a-4a7e-9b4e-58bfc75527f2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 102, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# With polar coordinates (regression)\n", "\n", "gggrid([\n", " get_oriented_plot(geom_band, band_data) + \\\n", " coord_polar(ylim=[-6, 6]) + \\\n", " theme(axis_title='blank'),\n", " get_oriented_plot(geom_band, band_data, swap=True, expected_text=\"correct plot\") + \\\n", " coord_polar(xlim=[-6, 6]) + \\\n", " theme(axis_title='blank'),\n", "], ncol=3)" ] }, { "cell_type": "markdown", "id": "fd10435e-4bda-4c29-96ef-31584c9fc812", "metadata": {}, "source": [ "## [ggplot2-like examples](https://ggplot2.tidyverse.org/reference/geom_boxplot.html#ref-examples)" ] }, { "cell_type": "code", "execution_count": 103, "id": "b8b4cc8d-e4df-4215-b098-c386607ad46a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 103, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot2_plot = ggplot(df, aes(\"class\", \"hwy\"))\n", "ggplot2_plot + geom_boxplot()" ] }, { "cell_type": "code", "execution_count": 104, "id": "177118a1-d78e-4e40-9ab2-84d5f7877eea", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 104, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Orientation follows the discrete axis\n", "ggplot(df, aes(\"hwy\", \"class\")) + geom_boxplot()" ] }, { "cell_type": "code", "execution_count": 105, "id": "1622253f-f04c-4201-8d7e-6b365b563d3d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 105, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot2_plot + geom_boxplot(varwidth=True)" ] }, { "cell_type": "code", "execution_count": 106, "id": "97581d56-ce74-4167-ac51-769b4e136d15", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 106, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot2_plot + geom_boxplot(fill=\"white\", color=\"#3366FF\")" ] }, { "cell_type": "code", "execution_count": 107, "id": "fa0279a5-4aba-4442-bc15-73aa63dee466", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 107, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# By default, outlier points match the colour of the box. Use outlier_color to override\n", "ggplot2_plot + geom_boxplot(outlier_color=\"red\", outlier_shape=1)" ] }, { "cell_type": "code", "execution_count": 108, "id": "72486b14-dcf1-448d-9060-484d2557f824", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 108, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Remove outliers when overlaying boxplot with original data points\n", "ggplot2_plot + geom_boxplot(outlier_color=\"transparent\") + geom_jitter(width=0.2, seed=42)" ] }, { "cell_type": "code", "execution_count": 109, "id": "bdffea02-6f75-4f0f-b131-171cb78f6fde", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 109, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Boxplots are automatically dodged when any aesthetic is a factor\n", "ggplot2_plot + geom_boxplot(aes(color=\"drv\"))" ] }, { "cell_type": "code", "execution_count": 110, "id": "34d636cd-9587-4b42-915f-ab7ddde397fd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 110, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# It's possible to draw a boxplot with your own computations if you use stat=\"identity\":\n", "def get_ggplot2_identity_data(*, seed=42):\n", " np.random.seed(seed)\n", " y = np.random.normal(size=100)\n", " return {\n", " 'x': [1],\n", " 'y0': [float(min(y))],\n", " 'y25': [float(np.quantile(y, .25))],\n", " 'y50': [float(np.median(y))],\n", " 'y75': [float(np.quantile(y, .75))],\n", " 'y100': [float(max(y))],\n", " }\n", "\n", "ggplot(get_ggplot2_identity_data(), aes(x='x')) + \\\n", " geom_boxplot(aes(ymin='y0', lower='y25', middle='y50', upper='y75', ymax='y100'),\n", " stat='identity')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.16" } }, "nbformat": 4, "nbformat_minor": 5 }